crispr_analysis_utils.guide_alignment.summary¶
crispr_analysis_utils.guide_alignment.summary ¶
Per-guide classes, and the guide alignment's output tables.
A guide's class counts its best matches whose genomic PAM matches: unique
with exactly one, multi with more, no_site with none. Best means the
fewest mismatches, which only a tolerated 5' position can carry, so without
scan_guides's tolerate_5p it is simply every match with a PAM. A match
whose PAM does not match is still written, with pam_matches FALSE, and
counted nowhere; best_site marks the rows the class counts. An entry that duplicates an earlier one's sequence gets that
entry's sites.
Coordinates are 0-based and half-open on the reference's forward strand, and
the protospacer excludes the PAM and any base 5' of it. The target site is a
boundary b 3 bases 5' of the PAM (end - 3 on +, start + 3 on
-). A nuclease cuts between b - 1 and b; a dCas9 only sits there,
so the name says where the site is, not what happens to it. In the tables, a value that
does not apply is an empty field, and booleans are TRUE or FALSE.
GROUPS
module-attribute
¶
GROUPS = (('from the guide table, before anything is aligned', 6), ('about the whole guide, repeated on each of its rows', 5), ("about this row's match; empty when the guide matches nowhere", 11))
The column groups, in order, and how many columns each has.
COLUMNS
module-attribute
¶
COLUMNS = {'guide_id': 'The sequence that was aligned, ending in the PAM pattern. Identifies the guide.', 'alias': 'Name for the guide from the input table.', 'accession': "A stable id for the protospacer, the same wherever that target is used. Two guides differing only 5' of the protospacer share it.", 'spacer': "The protospacer: guide_id without the PAM pattern or any base 5' of it.", 'oligo': "The sequence the library ordered, without the PAM. It differs from the spacer when the entry carries a base 5' of the protospacer, such as a G added for U6 transcription.", 'n_oligos': "How many library entries share this spacer. Above one, a feature reference built on the spacer cannot tell them apart, so the counts are a sum: expect roughly that multiple of a guide ordered once. Typically the two are a 20-mer and the same spacer with a 5' G, which no read can tell apart when the leader ends in a poly-G run.", 'site_class': 'unique, multi or no_site: how many PAM-bearing places this guide matches.', 'n_matches': 'How many places the protospacer matches, whether or not a PAM sits beside it. That is one row each below, unless the run was given --pam-only, which writes only the rows with a PAM.', 'n_target_sites': 'How many of those have a PAM, so Cas9 can act there.', 'orientation': "Whether the sequence reads 5' to 3': forward, reverse_complement, no_pam, no_match, or not_checked.", 'orientation_evidence': 'Only for reverse_complement. distinct: the reversed reading was a different sequence. ambiguous: it was just the reverse complement, which a chance CCN upstream looks identical to.', 'chr': 'Contig of this match.', 'start': 'First base of the protospacer, 0-based.', 'end': 'One past its last base, so the protospacer is [start, end).', 'strand': "Strand the protospacer reads 5' to 3' on.", 'target_site': 'Where Cas9 acts: the boundary 3 bases from the PAM. A nuclease cuts between target_site - 1 and target_site; dCas9 binds without cutting.', 'pam_matches': 'TRUE when the genomic PAM fits the pattern, so Cas9 can act here.', 'best_site': "TRUE for the guide's best PAM-bearing sites, the ones site_class counts: those with the fewest mismatches. A site found only by tolerating a 5' mismatch is FALSE when the guide also pairs throughout somewhere. Element mapping and gene annotation read only these rows.", 'paired_5p': "TRUE when the guide's base 5' of the protospacer is the base the genome holds there, so it pairs and the site is one longer than the spacer. Empty when the guide has no such base, or the match sits too close to a contig end for it to have been read.", 'genomic_5p_base': "What the genome holds under the guide's base 5' of the protospacer, to compare with the first base of oligo. A guide G over some other genomic base is the G a U6 construct adds; any other disagreement is a mismatch the design did not intend. Cas9 tolerates either, the position being the PAM-distal one, so this says which it was rather than whether the guide cuts. Empty when the guide has no base 5' of its protospacer, or the match sits too close to a contig end for the base to have been read.", 'genomic_spacer_5p': 'What the genome holds at the PAM-distal protospacer positions the run was told to tolerate with --tolerate-5p, so a difference from the start of spacer is a position the design did not pair. Cas9 acts there either way, which is why the site is reported; a guide whose position 1 was written G is the usual reason. Empty unless the run tolerated a position.', 'mapped_sequence': "What the genome holds here, to compare against guide_id: the protospacer and the real PAM, keeping the 5' base only where the genome has that same base."}
Every column of guide_genome_annotation.tsv, and what it holds.
BED_COLUMNS
module-attribute
¶
BED_COLUMNS = {'chr': 'Contig of the match.', 'start': "First base of what pairs, 0-based: the protospacer, and the base 5' of it where that one pairs too.", 'end': 'One past its last base.', 'name': 'The protospacer, as spacer in the metadata table.', 'score': 'Always 0; BED6 wants the field.', 'strand': "Strand the protospacer reads 5' to 3' on."}
The six fields of guide_mapping.bed, which has no header of its own.
GuideSummary
dataclass
¶
One guide's class, site counts and, when unique, its site.
Attributes:
-
guide_id(str) –The sequence that was aligned: the input sequence and the PAM.
-
alias(str) –The name the guide table gives this entry.
-
spacer(str) –The spacer, 5' to 3'.
-
oligo(str) –The sequence the library ordered, without the PAM: the spacer plus any base 5' of it.
-
n_oligos(int) –How many library entries carry this spacer. More than one means a feature reference built on the spacer merges them, so the counts are a sum and are not comparable with a guide ordered once.
-
mapped_sequence(str | None) –The guide's bases that pair with the genome at the unique site, as in
Site.mapped_sequence; None unless the class isunique. -
site_pam(str | None) –The genomic PAM of the unique site, in guide orientation; None unless the class is
unique. -
has_perfect_site(bool) –Whether the guide has at least one PAM-bearing site it pairs with throughout. It is
site_classother thanno_siteunless the scan tolerated a 5' mismatch and the guide's best site carries one. -
guide_chr(str | None) –The unique site's contig; None unless unique.
-
guide_start(int | None) –The unique site's protospacer start; None unless unique.
-
guide_end(int | None) –The unique site's protospacer end; None unless unique.
-
strand(str | None) –The unique site's strand; None unless unique.
-
target_site(int | None) –The unique site's target boundary (see the module description); None unless unique.
-
site_class(str) –unique,multiorno_site, counting the guide's best PAM-bearing sites (see the module description). -
orientation(str) –The orientation verdict, or
not_checked. -
orientation_evidence(str | None) –For a
reverse_complementguide, whether that reading was a distinct sequence or only the spacer's reverse complement; None otherwise. -
extra_5p(bool) –Whether the guide's site reads carry an added 5' G.
-
min_mismatches(int | None) –The fewest spacer mismatches among the sites with a matching PAM; None without any.
-
n_matches(int) –Every exact match of the spacer, whether or not a PAM sits beside it. More than one means the spacer occurs more than once in the genome, which
site_classdoes not say: that counts PAM-bearing sites only. -
n_sites(tuple[int, ...]) –Sites with a matching PAM by spacer mismatches:
n_sites[m]sites havem, formfrom 0 tomax_mismatches. -
input_sequence(str) –The sequence as given in the guide table, uppercased.
Source code in src/crispr_analysis_utils/guide_alignment/summary.py
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 | |
summarize ¶
summarize(guides: Sequence[Guide], sites: Mapping[int, Sequence[Site]], orientation: Mapping[int, str] | None = None, *, evidence: Mapping[int, str | None] | None = None, pam: str = 'NGG', max_mismatches: int = 3, matches: Mapping[int, int] | None = None, tolerate_5p: int = 0) -> list[GuideSummary]
Classify every guide from its sites.
Parameters:
-
guides(Sequence[Guide]) –The library, as returned by
read_guides. -
sites(Mapping[int, Sequence[Site]]) –The kept sites by guide row, as in
SiteResult.sites. -
orientation(Mapping[int, str] | None, default:None) –The orientation verdicts by guide row, as in
ScanResult.verdicts; None when the check did not run. -
pam(str, default:'NGG') –The PAM pattern the sites were classified with.
-
max_mismatches(int, default:3) –The mismatch limit the sites were kept with.
-
matches(Mapping[int, int] | None, default:None) –How many places each guide's protospacer occurs, as in
ScanResult.matches. None counts the sites given instead, which is right only when every match became one: after apam_onlyscan it would count the PAM-bearing sites and call them every match. -
tolerate_5p(int, default:0) –How many mismatches a site may carry and still count toward the class, as
scan_guideswas told to tolerate at the protospacer's PAM-distal end. At 0 only the sites a guide pairs with throughout count, which is every site of a scan that tolerated nothing.
Returns:
-
list of GuideSummary–One per guide, in library order, duplicates included.
Raises:
-
ValueError–If
pamfailsvalidate_pattern,max_mismatchesis negative, a site has more mismatches thanmax_mismatchesor a PAM class that is neitherpamnornone, a guide is a duplicate of an alias not in the library, ororientationlacks a guide's verdict.
Source code in src/crispr_analysis_utils/guide_alignment/summary.py
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 | |
fan_out_sites ¶
fan_out_sites(guides: Sequence[Guide], sites: Mapping[int, Sequence[Site]]) -> list[Site]
Every guide's sites, in library order, duplicates included.
Parameters:
-
guides(Sequence[Guide]) –The library, as returned by
read_guides. -
sites(Mapping[int, Sequence[Site]]) –The kept sites by guide row, as in
SiteResult.sites.
Returns:
-
list of Site–For each distinct
Guide.guide_idin turn, the sites of its row, or of the entry it duplicates, withSite.guide_idset to it. Entries that share a sequence are one guide, so their sites are written once.
Source code in src/crispr_analysis_utils/guide_alignment/summary.py
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 | |
guide_columns ¶
guide_columns() -> list[str]
The columns of guide_genome_annotation.tsv, in order.
One row per library entry per site, so the guide's own columns repeat on every site it has, and an entry with no site gets one row whose site columns are empty.
Returns:
-
list of str–The column names: the guide, then what the whole guide is, then the one site the row is about.
Source code in src/crispr_analysis_utils/guide_alignment/summary.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
write_guides_tsv ¶
write_guides_tsv(path: str | PathLike[str], guides: Sequence[Guide], summaries: Sequence[GuideSummary], sites: Mapping[int, Sequence[Site]]) -> None
Write guide_genome_annotation.tsv: every entry, a row per site.
Parameters:
-
path(str | PathLike[str]) –The file to write.
-
guides(Sequence[Guide]) –The library, as returned by
read_guides. -
summaries(Sequence[GuideSummary]) –The guides, as returned by
summarize, in the same order. -
sites(Mapping[int, Sequence[Site]]) –The sites by guide row, as in
ScanResult.sites.
Raises:
-
ValueError–If
summariesis not one per guide.
Notes
write_guides_bed writes the same sites as a BED.
n_matches is not site_class: it counts every place the protospacer
occurs, while multi counts only the matches with a PAM beside them, so
a guide can match many places and still bear a PAM at one. It counts them
all after a pam_only scan too, which is the only place that count
survives.
Source code in src/crispr_analysis_utils/guide_alignment/summary.py
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 | |
write_guides_bed ¶
write_guides_bed(path: str | PathLike[str], guides: Sequence[Guide], sites: Mapping[int, Sequence[Site]], bgzip: bool = False) -> Path
Write guide_mapping.bed: every site a guide could act at.
Parameters:
-
path(str | PathLike[str]) –The file to write.
-
guides(Sequence[Guide]) –The library, as returned by
read_guides. -
sites(Mapping[int, Sequence[Site]]) –The sites by guide row, as in
ScanResult.sites. -
bgzip(bool, default:False) –Write
pathwith.gzappended, block-compressed, and build its tabix index beside it. The rows are already in coordinate order, so nothing is sorted twice.
Returns:
-
Path–The file written, which carries
.gzunderbgzip.
Notes
BED6 without a header, fields as in BED_COLUMNS, one row per site whose
genomic PAM matches, so a spacer with two PAM-bearing sites gets a row for
each. The interval covers what pairs, so it is one longer wherever the
guide's 5' base pairs too, and the table's paired_5p says where that
is. The name field stays the protospacer either way, which is what
groups a guide's rows when one of its sites pairs there and another does
not. Sorted by contig, then position.
A match with no PAM
is not somewhere Cas9 can act, so it is left out;
guide_genome_annotation.tsv has them all.
Source code in src/crispr_analysis_utils/guide_alignment/summary.py
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 | |
write_columns_yaml ¶
write_columns_yaml(path: str | PathLike[str]) -> None
Write guide_genome_annotation_columns.yaml: what every column holds.
Parameters:
-
path(str | PathLike[str]) –The file to write.
Notes
Generated from COLUMNS and BED_COLUMNS, so it cannot drift from the
tables themselves.
Source code in src/crispr_analysis_utils/guide_alignment/summary.py
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 | |
write_qc_tsv ¶
write_qc_tsv(path: str | PathLike[str], summaries: Sequence[GuideSummary], *, counts: Mapping[str, Mapping[str, int]] | None = None) -> None
Write qc.tsv: the counts worth checking on a run.
Parameters:
-
path(str | PathLike[str]) –The file to write.
-
summaries(Sequence[GuideSummary]) –The guides, as returned by
summarize. -
counts(Mapping[str, Mapping[str, int]] | None, default:None) –Further counts by section name, such as
{"site_search": SiteResult.counts()}.
Raises:
-
ValueError–If a summary has an unknown class or verdict, or a
countssection reuses a built-in section name.
Notes
Three columns, section, name and value. Section guides
(n_entries, n_guides, n_shared_spacers); section class,
one row per site class; section orientation, one row per verdict,
not_checked included; then each counts section. The class rows and
the orientation rows each sum to n_entries. The run's parameters are
not here: they belong to the step's metadata file.
Source code in src/crispr_analysis_utils/guide_alignment/summary.py
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 | |