| name | bio-genome-engineering-off-target-prediction |
| description | Predict CRISPR off-target sites using Cas-OFFinder and CFD scoring algorithms. Identify potential unintended cleavage sites genome-wide and assess guide specificity. Use when evaluating guide RNA specificity or selecting guides with minimal off-target risk. |
| tool_type | cli |
| primary_tool | Cas-OFFinder |
Version Compatibility
Reference examples tested with: pandas 2.2+
Before using code patterns, verify installed versions match. If versions differ:
- Python:
pip show <package> then help(module.function) to check signatures
- CLI:
<tool> --version then <tool> --help to confirm flags
If code throws ImportError, AttributeError, or TypeError, introspect the installed
package and adapt the example to match the actual API rather than retrying.
Off-Target Prediction
"Check my guide RNA for off-target sites" → Search the genome for potential unintended cleavage sites allowing mismatches, then score each off-target by cutting frequency determination (CFD) to assess guide specificity.
- CLI:
cas-offinder for genome-wide off-target search
- Python: CFD scoring with mismatch penalty matrices
Cas-OFFinder (CLI)
Cas-OFFinder searches genomes for potential off-target sites allowing mismatches.
cas-offinder input.txt C output.txt
cas-offinder input.txt G output.txt
Cas-OFFinder Input Preparation
def prepare_cas_offinder_input(guides, genome_path, max_mismatches=4, pam='NGG'):
'''Prepare Cas-OFFinder input file
Args:
guides: List of 20nt guide sequences
genome_path: Path to genome directory with .2bit or indexed fasta
max_mismatches: Maximum mismatches to search (0-6 typical)
More mismatches = slower but more comprehensive
4 mismatches: good balance of speed and sensitivity
pam: PAM sequence (NGG for SpCas9)
'''
lines = [genome_path]
pattern = 'N' * 20 + pam
lines.append(pattern)
for guide in guides:
lines.append(f'{guide}NNN {max_mismatches}')
return '\n'.join(lines)
Parse Cas-OFFinder Output
import pandas as pd
def parse_cas_offinder_output(output_file):
'''Parse Cas-OFFinder results
Output columns:
- Guide: Query guide sequence
- Chromosome: Target chromosome
- Position: Genomic position (0-based)
- Sequence: Off-target sequence found
- Strand: + or -
- Mismatches: Number of mismatches
'''
columns = ['guide', 'chrom', 'position', 'sequence', 'strand', 'mismatches']
df = pd.read_csv(output_file, sep='\t', header=None, names=columns)
df = df.sort_values('mismatches')
return df
def summarize_off_targets(df):
'''Summarize off-target counts by mismatch number'''
summary = df.groupby(['guide', 'mismatches']).size().unstack(fill_value=0)
summary['specificity'] = 1 / (1 + summary.get(0, 0) * 100 +
summary.get(1, 0) * 10 +
summary.get(2, 0))
return summary
CFD Score Calculation
CFD_MISMATCH_SCORES = {
(1, 'C', 'A'): 0.5, (1, 'C', 'G'): 0.7, (1, 'C', 'T'): 0.3,
(1, 'G', 'A'): 0.4, (1, 'G', 'C'): 0.6, (1, 'G', 'T'): 0.3,
(20, 'C', 'A'): 0.9, (20, 'C', 'G'): 0.95, (20, 'C', 'T'): 0.85,
}
CFD_PAM_SCORES = {
'AGG': 0.26, 'CGG': 0.11, 'TGG': 0.02,
: , : , : ,
: , : , : ,
}
():
score =
i, (g, t) ((guide, off_target[:]), ):
g != t:
key = (i, g, t)
penalty = CFD_MISMATCH_SCORES.get(key, )
score *= penalty
off_pam = off_target[:]
off_pam != off_pam CFD_PAM_SCORES:
score *= CFD_PAM_SCORES[off_pam]
score
Aggregate Off-Target Score
def calculate_guide_specificity(guide, off_targets):
'''Calculate aggregate specificity score for a guide
Uses sum of CFD scores for all off-targets.
Lower aggregate = more specific guide.
Specificity score interpretation:
- >0.9: Highly specific (excellent)
- 0.7-0.9: Specific (good)
- 0.5-0.7: Moderate specificity (acceptable)
- <0.5: Poor specificity (consider alternatives)
'''
cfd_sum = sum(calculate_cfd_score(guide, ot['sequence'], ot.get('pam', 'NGG'))
for ot in off_targets)
specificity = 1 / (1 + cfd_sum)
return specificity
CRISPOR-style Analysis
Goal: Run a complete off-target analysis pipeline from a single guide sequence to a scored, ranked list of potential off-target sites.
Approach: Prepare a Cas-OFFinder input file, run the genome-wide mismatch search, parse the tabular output, calculate CFD scores for each hit, and flag high-risk off-targets by cleavage probability.
def analyze_guide_specificity(guide_seq, genome_fasta, max_mm=4):
'''Full off-target analysis workflow
1. Run Cas-OFFinder to find potential sites
2. Calculate CFD scores for each site
3. Compute aggregate specificity
4. Flag high-risk off-targets
'''
import subprocess
import tempfile
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
f.write(f'{genome_fasta}\n')
f.write('N' * 20 + 'NGG\n')
f.write(f'{guide_seq}NNN {max_mm}\n')
input_file = f.name
output_file = input_file.replace('.txt', '_out.txt')
subprocess.run(['cas-offinder', input_file, 'C', output_file], check=True)
off_targets = parse_cas_offinder_output(output_file)
off_targets['cfd_score'] = off_targets.apply(
lambda row: calculate_cfd_score(guide_seq, row['sequence']), axis=1
)
return off_targets
Related Skills
- genome-engineering/grna-design - Design guides before off-target check
- variant-calling/variant-annotation - Check if off-targets overlap known variants
- genome-intervals/bed-file-basics - Intersect off-targets with genomic features