crispr_analysis_utils.guide_alignment.scan¶
crispr_analysis_utils.guide_alignment.scan ¶
The genome scan: every exact site of every guide, read from the reference.
A guide is designed, not sequenced, so its own site is an exact match of the spacer. One pass of the compiled core finds every such match on both strands and reads the bases around it, which answers all three questions at once: where the spacer matches, what sits 3' of it (the PAM) and what sits 5' of it (the base an added G lands on).
Orientation falls out of the same pass, because both directions go into the
same table: each guide contributes its spacer and the spacer of its reverse
complement. An entry is reverse_complement only when that second sequence
matches somewhere with a PAM and the first does not. Reading CCN 5' of a
match is not the test -- it happens by chance one time in sixteen -- and for a
guide carrying an added G the reversed spacer is not even the reverse
complement of the spacer, since the trim moves to the other end.
ScanResult
dataclass
¶
Every guide's exact sites, its orientation, and what was set aside.
Attributes:
-
sites(dict[int, list[Site]]) –The sites of each guide row, in reference order.
-
verdicts(dict[int, str]) –Each guide row's orientation verdict.
-
evidence(dict[int, str | None]) –For a
reverse_complementrow, whether the reversed reading was a distinct sequence or only the spacer's reverse complement; None for every other row. -
matches(dict[int, int]) –How many places each guide row's protospacer occurs, counted whether or not the site was kept. Under
pam_onlyit is the only record of the sites that were not. -
n_matches(int) –Exact spacer matches found, before any were set aside.
-
n_off_contig_end(int) –Matches whose PAM would run off the end of their contig.
-
n_no_pam(int) –Matches kept with a genomic PAM that matches no pattern. Under
pam_onlythese are counted and not written, so the table holdsn_sites - n_no_pamrows. -
n_sites(int) –Matches kept.
Source code in src/crispr_analysis_utils/guide_alignment/scan.py
40 41 42 43 44 45 46 47 48 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 | |
counts ¶
counts() -> dict[str, int]
The counts, for qc.tsv and the step's metadata.
Source code in src/crispr_analysis_utils/guide_alignment/scan.py
79 80 81 82 83 84 85 86 | |
scan_guides ¶
scan_guides(guides: Sequence[Guide], reference: str | PathLike[str], *, pam: str = 'NGG', contigs: Collection[str] | None = None, pam_only: bool = False, tolerate_5p: int = 0) -> ScanResult
Find every exact site of every guide in reference.
Parameters:
-
guides(Sequence[Guide]) –The library, as returned by
read_guides. -
reference(str | PathLike[str]) –The reference FASTA. It is read as text, so it must not be compressed.
-
pam(str, default:'NGG') –The PAM pattern, in IUPAC codes, 3' of the protospacer.
-
contigs(Collection[str] | None, default:None) –If given, read only these contigs.
-
pam_only(bool, default:False) –Keep only the matches whose genomic PAM matches
pam. The core drops the rest as it finds them, so they never cross into Python and nothing holds them. Every match is still counted, inScanResult.matchesandn_matches: a short spacer matches everywhere, and the places it cannot be cut at are the bulk of them, but how many there were is worth knowing. -
tolerate_5p(int, default:0) –How many bases at the protospacer's PAM-distal end need not pair with the genome. The exact search is that much shorter, while the protospacer and its coordinates keep their declared length: 1 finds the site of a guide whose designer wrote a G at position 1 where the genome holds another base. What the genome holds there is reported in
Site.genomic_spacer_5pand counted nowhere, as the added G's base is.
Returns:
-
ScanResult–The sites of each guide row and its orientation verdict.
Raises:
-
ValueError–If
pamis not IUPAC codes, the guides' spacers differ in length, ortolerate_5pis negative or leaves no bases to search. -
OSError–If
referencecannot be read.
Notes
Each distinct search core is scanned once and its matches are given to every guide that uses it, so two entries differing only in an added G cost one search between them.
pam_only shrinks what is held and what is written, not what is
searched: every match is found and counted either way. The counters
come from the scan rather than from the matches returned, which is what
lets them report what they never handed back.
Source code in src/crispr_analysis_utils/guide_alignment/scan.py
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 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 | |