In-Silico Mutagenesis¶
This tutorial demonstrates saturation mutagenesis analysis: systematically mutating each position in a DNA sequence to measure the effect on model predictions. This reveals critical nucleotides and functional regions.
Full Notebook¶
Prerequisites¶
uv pip install -e '.[base,inference,cuda124]'
Load Configuration and Model¶
from dnallm import load_config, load_model_and_tokenizer
configs = load_config("./inference_config.yaml")
model_name = "zhangtaolab/plant-dnagpt-BPE-promoter_strength_protoplast"
model, tokenizer = load_model_and_tokenizer(
model_name,
task_config=configs['task'],
source="modelscope"
)
Initialize Mutagenesis Analyzer¶
from dnallm import Mutagenesis
mutagenesis = Mutagenesis(config=configs, model=model, tokenizer=tokenizer)
Generate Saturation Mutagenesis Library¶
Replace each position with all four nucleotides:
sequence = (
"AATATATTTAATCGGTGTATAATTTCTGTGAAGATCCTCGATACTTCATATAAGAGATTTTGAGAGAGAGAGAGA"
"ACCAATTTTCGAATGGGTGAGTTGGCAAAGTATTCACTTTTCAGAACATAATTGGGAAACTAGTCACTTTACTAT"
"TCAAAATTTGCAAAGTAGTC"
)
mutagenesis.mutate_sequence(sequence, replace_mut=True)
print(mutagenesis.sequences)
Evaluate Mutations¶
Compute predictions for all mutated sequences:
preds = mutagenesis.evaluate(strategy="mean")
Visualize Mutation Effects¶
pmut = mutagenesis.plot(preds, save_path="plot_mut_effects.pdf")
The heatmap shows how each nucleotide substitution at each position affects the predicted score. Bright spots indicate critical positions where mutations cause large changes.