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 the matches whose genomic PAM matches: unique with
exactly one, multi with more, no_site with none. A match whose PAM does
not is still written, with pam_matches FALSE, and counted nowhere. 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", 7))
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. Here the second entry is the same spacer with a 5' G, which no read can be assigned to on its own, because 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, which is how many rows this guide has below.', '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.', '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 the protospacer, 0-based.', '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 perfect site with a matching PAM.
-
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. -
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
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 | |
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) -> 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.
Returns:
-
list of GuideSummary–One per guide, in library order, duplicates included.
Raises:
-
ValueError–If the PAM patterns fail
validate_pams,max_mismatchesis negative, a site has more mismatches thanmax_mismatchesor a PAM class that is neither one of the patterns nornone, 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
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 | |
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
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 | |
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
367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
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.
Source code in src/crispr_analysis_utils/guide_alignment/summary.py
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 | |
write_guides_bed ¶
write_guides_bed(path: str | PathLike[str], guides: Sequence[Guide], sites: Mapping[int, Sequence[Site]]) -> None
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.
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 name field is the protospacer, which is the same on every row
of a guide that matches more than once. 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
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 | |
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
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 | |
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
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 | |