Skip to content

crispr_analysis_utils.guide_alignment.sites

crispr_analysis_utils.guide_alignment.sites

One genomic site of a guide, as the scan reports it.

NO_PAM_CLASS module-attribute

NO_PAM_CLASS = 'none'

The Site.pam_class of a site whose genomic PAM matches no pattern.

Site dataclass

One genomic site of a guide, as verified against the reference.

Attributes:

  • guide_id (str) –

    The guide's id.

  • chr (str) –

    The contig.

  • start (int) –

    The first base of the protospacer, 0-based.

  • end (int) –

    One past the last base of the protospacer: the protospacer is [start, end).

  • strand (str) –

    + or -: the strand the protospacer reads 5' to 3' on.

  • pam (str) –

    The genomic PAM, uppercased, in guide orientation.

  • pam_class (str) –

    The first pattern the genomic PAM matches, trying the PAM and then any alternatives in their order, or none. A genomic N matches only an N of the pattern.

  • n_mismatches (int) –

    The mismatches between the spacer and the genomic protospacer. A genomic N counts as one; the added G never counts.

  • mismatch_positions (tuple[int, ...]) –

    The 1-based spacer positions of those mismatches, counted from the guide's 5' end.

  • mapped_sequence (str) –

    What was aligned here, 5' to 3': the base 5' of the protospacer where the genome has that same base, the protospacer, then the genomic PAM.

  • genomic_protospacer (str) –

    The reference bases of the protospacer, uppercased, in guide orientation.

  • genomic_5p_base (str | None) –

    The genomic base under the sequence's base 5' of the protospacer, in guide orientation; None when it has none.

  • genomic_spacer_5p (str) –

    The genome's bases under the PAM-distal protospacer positions the scan was told to tolerate, in guide orientation, so they differ from the start of the spacer exactly where the design did not pair. Empty when the scan tolerated none, which is every run that did not ask.

Source code in src/crispr_analysis_utils/guide_alignment/sites.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
@dataclass(frozen=True)
class Site:
    """One genomic site of a guide, as verified against the reference.

    Attributes
    ----------
    guide_id
        The guide's id.
    chr
        The contig.
    start
        The first base of the protospacer, 0-based.
    end
        One past the last base of the protospacer: the protospacer is
        ``[start, end)``.
    strand
        ``+`` or ``-``: the strand the protospacer reads 5' to 3' on.
    pam
        The genomic PAM, uppercased, in guide orientation.
    pam_class
        The first pattern the genomic PAM matches, trying the PAM and then any
        alternatives in their order, or ``none``. A genomic ``N`` matches only
        an ``N`` of the pattern.
    n_mismatches
        The mismatches between the spacer and the genomic protospacer. A
        genomic ``N`` counts as one; the added G never counts.
    mismatch_positions
        The 1-based spacer positions of those mismatches, counted from the
        guide's 5' end.
    mapped_sequence
        What was aligned here, 5' to 3': the base 5' of the protospacer where
        the genome has that same base, the protospacer, then the genomic PAM.
    genomic_protospacer
        The reference bases of the protospacer, uppercased, in guide
        orientation.
    genomic_5p_base
        The genomic base under the sequence's base 5' of the protospacer, in
        guide orientation; None when it has none.
    genomic_spacer_5p
        The genome's bases under the PAM-distal protospacer positions the scan
        was told to tolerate, in guide orientation, so they differ from the
        start of the spacer exactly where the design did not pair. Empty when
        the scan tolerated none, which is every run that did not ask.
    """

    guide_id: str
    chr: str
    start: int
    end: int
    strand: str
    pam: str
    pam_class: str
    n_mismatches: int
    mismatch_positions: tuple[int, ...]
    mapped_sequence: str
    genomic_protospacer: str
    genomic_5p_base: str | None
    genomic_spacer_5p: str = ""

    @property
    def paired_5p(self) -> bool | None:
        """Whether the guide's base 5' of the spacer pairs with the genome.

        None when there is nothing to ask: a guide with no 5' base, or a
        match so close to a contig end that the base under it was never
        read. A 5' base that pairs is recognised like any other, which is
        why the BED's interval covers it and the declared protospacer does
        not move.
        """
        if self.genomic_5p_base is None:
            return None
        return len(self.mapped_sequence) > len(self.genomic_protospacer) + len(self.pam)

paired_5p property

paired_5p: bool | None

Whether the guide's base 5' of the spacer pairs with the genome.

None when there is nothing to ask: a guide with no 5' base, or a match so close to a contig end that the base under it was never read. A 5' base that pairs is recognised like any other, which is why the BED's interval covers it and the declared protospacer does not move.