LSMA

LONDON SCHOOL OF MULTIOMICS & AI

Free course

Free course

0 of 73 lessons

Lesson 11 of 12

Module 8 · AI for biology

AI for gene editing: designing CRISPR guides

AI for gene editing: designing CRISPR guides

AI for gene editing: designing CRISPR guides

A guide RNA is twenty nucleotides that decide where Cas9 cuts. Scan a sequence for PAM sites yourself, apply the design rules, and see where learned scoring models help and where they do not.

⏱ 14 min readModule 8 · AI for biologyFree
Lesson at a glance4 steps · about 14 min
  1. Cutting DNA at one chosen place
  2. Choosing among the candidates
  3. Learned scoring models
  4. Finding candidate guides in a sequence

Cutting DNA at one chosen place

CRISPR-Cas9 is a system borrowed from bacteria, where it defends against viruses. Two parts matter here. Cas9 is an enzyme that cuts double-stranded DNA. The guide RNA is a short RNA that Cas9 carries; about 20 of its bases are complementary to the target DNA, and they decide where the cut happens. Change those 20 bases and you point the same enzyme at a different place in the genome.

The target site in the DNA is called the protospacer: 20 nucleotides that match the guide. Next to it, the genome must carry a PAM (protospacer adjacent motif). For the commonly used Cas9 from Streptococcus pyogenes, the PAM is NGG: any base, then two Gs, immediately after the protospacer. Without a PAM, Cas9 will not cut, however well the guide matches. The PAM is part of the genome, not of the guide.

Cas9 cuts both strands about three bases inside the protospacer from the PAM end. The cell then repairs the break, and the repair is what actually edits the gene: joining the ends back together often inserts or deletes a few bases, which can disable the gene, while supplying a template lets the cell copy in a chosen sequence. Newer systems such as base editors and prime editors change bases without a full double-strand break, but they still find their target in the same way.

The two repair routes have names. Non-homologous end joining (NHEJ) sticks the broken ends back together quickly and often imperfectly, leaving a small insertion or deletion, an indel. Homology-directed repair (HDR) copies a template that matches the sequence on both sides of the break, and is how a chosen change is written in; it is much less frequent in most cells. Why does a small indel disable a gene? You saw in Finding genes and annotating a genome that a coding sequence is read three bases at a time. An indel whose length is not a multiple of three shifts the reading frame, so every codon after it is read wrongly and a stop codon usually turns up soon. An indel of exactly three or six bases keeps the frame and may leave a working protein, which is one reason edited cells must be sequenced, not assumed.

Because DNA is double-stranded, a PAM can face either way. A CCN on the strand you are reading is an NGG on the other strand, and gives a guide for the reverse strand. Any guide-finding program must therefore scan both strands, as the code below does.

Cas9, the guide RNA and the PAM
Cas9 carries a single guide RNA whose spacer pairs with the target sequence in the genome. The PAM sits immediately beyond the target and belongs to the genome, not the guide; the cuts fall inside the target, close to it. Schematic, not to scale. Created in BioRender.com.

How to read the figure. Read the top strand left to right: twenty nucleotides of protospacer, then the three-letter PAM in the vermilion box. The dashed line marks the cut, which falls inside the protospacer, three bases from the PAM end. The second strand runs the other way, so its PAMs show up as CCN when you read the top strand.

Choosing among the candidates

A typical gene offers dozens of PAM sites, so the real question is which guide to use. Two things decide it: whether the guide works where you want it to (on-target efficiency) and whether it also cuts somewhere you do not (off-target risk).

Simple rules of thumb for on-target efficiency, each a tendency rather than a law:

  • GC content around 40–70%. Very low GC binds weakly; very high GC can bind too tightly and can be hard to make.
  • No run of four or more Ts. Guides are usually transcribed from a U6 promoter by RNA polymerase III, and a run of Ts is its stop signal, so TTTT inside the protospacer cuts the guide short.
  • Position in the gene. To disable a gene, aim at an early coding exon shared by all transcripts; a cut in the last exon may leave a working protein.
  • Avoid common variants. A single-nucleotide polymorphism under the guide or in the PAM can stop the guide working in some people or cell lines.

The advice to aim early has a mechanism behind it. When a frameshift creates a premature stop codon well before the last exon, the cell usually detects the faulty messenger RNA and destroys it, a quality-control process called nonsense-mediated decay. So an early cut tends to remove the protein altogether, while a late one may produce a shortened protein that still does part of its job. To find an exon shared by all transcripts, look at the gene's transcripts in a genome browser such as Ensembl, which lists them side by side.

Off-target risk is about the rest of the genome. Cas9 tolerates some mismatches, so a site that differs from your guide by two or three bases may also be cut, especially when the differences are far from the PAM. The seed region, roughly the ten nucleotides nearest the PAM, matters most: mismatches there usually prevent cutting, while mismatches at the far end often do not. Assessing this means searching the whole genome for near matches, which is why guide design is done with a tool and a genome, not by hand.

Two cautions about that search. It covers the reference genome, and the cells you edit are not the reference: a cell line or a patient carries its own variants, which can create or remove off-target sites. And a computational list is a prediction. Where off-target effects matter, for example in work heading towards therapy, laboratories measure them directly with methods that find every place Cas9 actually cut, such as GUIDE-seq or CIRCLE-seq, and then sequence the most likely sites in the edited cells.

Go deeper: why near matches are unavoidable

How many near matches should a random 20-base guide expect in the human genome? Count the sequences within 3 mismatches of it: 1 exact, 20 × 3 = 60 with one mismatch, 190 × 9 = 1,710 with two and 1,140 × 27 = 30,780 with three. That is about 32,500 sequences, out of about 1.1 million million (4 to the power 20) possible 20-mers.

The genome has about 3.1 billion positions on each strand, 6.2 billion in total, and about one in sixteen is followed by NGG: roughly 390 million PAM sites. Multiply 390 million by 32,500 and divide by 1.1 million million: you get about 11. So even a guide with nothing special about it should expect around ten sites with three or fewer mismatches next to a PAM. Real genomes are repetitive, so the true number is often higher. Hence the genome-wide search, and the position-aware weighting of mismatches.

Learned scoring models

The rules above are coarse. Experiments that measured thousands of guides made it possible to learn the patterns instead: models trained on measured cutting efficiency score a new guide from its sequence, and separate models predict the chance of cutting at a given off-target site, weighting mismatches by position. Early versions used position-specific features and gradient boosting; later ones use convolutional networks of the kind you met in Deep learning on sequences: what the model actually learns, and some add the DNA's local context or chromatin state.

The input to these models is the same kind of representation you built in Turning sequences into numbers: features for machine learning: each of the 20 to 30 positions around the site is encoded as one of four bases, often with a few extra features such as GC content or predicted RNA folding. A learned model can then pick up preferences no simple rule captures, for instance that certain bases right next to the PAM are associated with more efficient cutting.

How well do they work? Honestly: better than the simple rules, and far from perfect. Scores from different models often disagree about the same guide, and performance drops when a model is applied to a cell type or measurement method unlike its training data. Everything in Judging AI claims in biology applies here: ask which dataset a score was trained on, which it was tested on, and whether the test guides were independent of the training ones. Treat any published number for a specific model with the caution that lesson deserves. In practice, use a scoring tool to shortlist, pick two or three guides, and test them.

Web tools such as CRISPOR and CHOPCHOP do all of this for you: paste a sequence or a gene name, choose a genome, and they return guides with efficiency scores, off-target lists and ready-made ordering sequences. The code below does the first, mechanical part by hand, so you can see what such a tool is doing before it adds its scores.

Key sources are Hsu et al. 2013, Nature Biotechnology, which mapped how Cas9 tolerates mismatches by position, and Doench et al. 2016, Nature Biotechnology, which introduced the Rule Set 2 efficiency score and the CFD off-target score. Haeussler et al. 2016, Genome Biology, compared many scores on independent data and built them into CRISPOR. A key finding to cite: efficiency scores predicted best when the test experiment used the same way of making the guide as the training data, for example a U6 promoter in cells. Choose a score trained on conditions like yours.

Finding candidate guides in a sequence

This lesson needs Biopython (!pip install biopython). The sequence is made up for teaching: it is not a real gene, so it has no real guides. Replace it with a stretch of a real exon and the same code applies.

Python
from Bio.Seq import Seq

# A made-up 90-nt stretch of DNA, written for teaching (not a real gene)
target = Seq("ATGCTGACCGTTAGCAAGTTTTCAGGATCCGAACTGGCTAAGCGTACGATTGCCAGTAC"
             "GGCGCCGCGGCCGCATTCCAGAGGTTACATG")

def find_guides(seq, strand):
    guides = []
    for i in range(len(seq) - 22):
        protospacer, pam = seq[i:i + 20], seq[i + 20:i + 23]
        if pam[1:] == "GG":                           # PAM is N-G-G
            guides.append((strand, i + 1, str(protospacer), str(pam)))
    return guides

candidates = find_guides(target, "+") + find_guides(target.reverse_complement(), "-")
print("Length:", len(target), "nt")
print("Plus strand:", sum(c[0] == "+" for c in candidates), "candidates")
print("Minus strand:", sum(c[0] == "-" for c in candidates), "candidates")
print("First one:", candidates[0])

What this does

  • Seq(...) makes a Biopython sequence object. Two strings written next to each other are joined, which lets a long sequence be split over two lines.
  • The loop slides along the sequence. At each position i it takes 20 nucleotides as the protospacer and the next 3 as a possible PAM. The stop at len(seq) - 22 keeps the 23-nucleotide window inside the sequence.
  • pam[1:] == "GG" ignores the first base (the N) and keeps the site only if the next two are Gs.
  • i + 1 converts Python's counting from zero into the usual biological numbering from one.
  • seq.reverse_complement() gives the other strand, written 5′ to 3′. Running the same search on it finds the reverse-strand guides. Their positions are counted along that strand, not the original.
Length: 90 nt Plus strand: 5 candidates Minus strand: 4 candidates First one: ('+', 4, 'CTGACCGTTAGCAAGTTTTC', 'AGG')

Reading the output

Nine candidate sites in 90 nucleotides, five on the plus strand and four on the minus strand. That density is normal: NGG occurs roughly once every sixteen positions by chance, and more often in GC-rich DNA, which is why most regions offer plenty of choice. The first candidate is printed in full: a protospacer starting at position 4 with the PAM AGG. Now the rules.

Python
def gc_percent(s):
    return 100 * (s.count("G") + s.count("C")) / len(s)

print(f"strand  pos  {'protospacer':20}  PAM  GC%  verdict")
for strand, pos, spacer, pam in candidates:
    gc = gc_percent(spacer)
    if "TTTT" in spacer:
        verdict = "drop: TTTT ends Pol III transcription"
    elif not 40 <= gc <= 70:
        verdict = "drop: GC outside 40-70%"
    else:
        verdict = "keep"
    print(f"{strand:^6}  {pos:3}  {spacer}  {pam}  {gc:3.0f}  {verdict}")

What this does

  • gc_percent counts the Gs and Cs and divides by the length, giving a percentage.
  • The if / elif chain applies the two rules in order, so a guide containing TTTT is reported for that reason even if its GC is also wrong.
  • 40 <= gc <= 70 is Python's way of writing "between 40 and 70 inclusive"; not turns it into "outside that range".
  • The f-string widths line the table up: {strand:^6} centres the strand in six characters, {gc:3.0f} prints the percentage with no decimals.
strand pos protospacer PAM GC% verdict + 4 CTGACCGTTAGCAAGTTTTC AGG 45 drop: TTTT ends Pol III transcription + 15 CAAGTTTTCAGGATCCGAAC TGG 45 drop: TTTT ends Pol III transcription + 39 TAAGCGTACGATTGCCAGTA CGG 45 keep + 47 CGATTGCCAGTACGGCGCCG CGG 70 keep + 61 GCGCCGCGGCCGCATTCCAG AGG 80 drop: GC outside 40-70% - 5 TAACCTCTGGAATGCGGCCG CGG 60 keep - 16 ATGCGGCCGCGGCGCCGTAC TGG 80 drop: GC outside 40-70% - 40 AATCGTACGCTTAGCCAGTT CGG 45 keep - 61 GGATCCTGAAAACTTGCTAA CGG 40 keep

Reading the output

Five of the nine candidates survive. Two are dropped for TTTT: the guides at plus-strand positions 4 and 15 both cover the same run of four Ts. Two more are dropped for GC above 70%, both in the GC-rich stretch in the middle of the sequence; one of them, at minus-strand position 16, is 80% GC. Note that the guide at plus-strand position 47 passes at exactly 70%, on the boundary, which is a reminder that these cut-offs are conventions.

Five candidates is where mechanical filtering ends and the real work begins. Each would now be scored for predicted efficiency, searched against the whole genome for near matches, and checked for position within the gene and for common variants. Then two or three would be made and tested in cells.

The code also leaves out some practical details that a design tool would handle. It reports where each protospacer starts, but not where the cut falls, three bases from the PAM end, which is what you need to check the cut lies inside the exon. Minus-strand positions are counted along the reverse complement, so they must be converted before comparing them with plus-strand positions: the first base of a guide at minus-strand position p in a 90-nucleotide sequence sits at plus-strand position 91 − p, and the guide runs leftwards from there. And because the U6 promoter prefers to start transcription with a G, guides that begin with another base are often ordered with an extra G added at the start.

Worked example · choosing between two guides

guide A: CGATTGCCAGTACGGCGCCG · GC 70% · no TTTT · 1 off-target site with 3 mismatches, all in the seed region
guide B: GGATCCTGAAAACTTGCTAA · GC 40% · no TTTT · 1 off-target site with 3 mismatches, all at the far end from the PAM

Both guides come from the filtered list above, and both pass the simple rules. A genome search returns one near match for each.

Step by step. The simple rules do not separate them: both sit inside 40–70% GC and neither contains TTTT, though A is at the top of the range and B at the bottom. So compare the off-target sites, and look at where the mismatches fall rather than counting them. Guide A's three mismatches are in the seed region, the ten nucleotides next to the PAM, where Cas9 is least tolerant, so that site is unlikely to be cut. Guide B's three mismatches are all at the far end, where Cas9 often tolerates differences, so its off-target site is the more worrying one despite having the same number of mismatches.

What the answer means. Guide A is the better first choice, on this evidence. But "three mismatches" alone would have made them look identical, and a tool that ranked by mismatch count would have missed the difference. Neither conclusion is final: order both, test them in cells, and confirm the edit by sequencing. A predicted score narrows the list; it does not decide the experiment.

Key point

A guide needs a PAM next to it, a sensible GC content and no run of four Ts; after that, what matters is where its near matches are in the genome and where the mismatches sit. Learned scores help you shortlist, not decide. Always test guides experimentally.

A second example: a guide with a perfect predicted efficiency score sits across a common single-nucleotide polymorphism. In cells carrying the other allele, the guide has a mismatch and may not cut at all, and the experiment fails for a reason no efficiency model was asked about. Check the variants under every guide before ordering.

Further reading · Module 8Addgene CRISPR guide: how the system works and how guides are chosen. · CRISPOR manual: what each efficiency and specificity score means. · CHOPCHOP: a web tool for guide design. · All reading for this course

Check your understanding

1. A 20-nucleotide stretch matches your intended target perfectly, but the three bases immediately after it are TGA. What happens?

2. Why are guides containing TTTT usually discarded?

3. Two off-target sites each differ from your guide by three nucleotides. Why might one matter far more than the other?

Up next

Project

Predict a protein's function class from its sequence

Ask BioTutor

Create a free website with Framer, the website builder loved by startups, designers and agencies.