import dgrec
dgrec.tr_score('AAATGATCGCCAAATCTGAACAGGAAATTGGCAAAGCAACCGCTAAATACTTTTTCTACTCAAACATTAT')0.84
DGRec is an in vivo hypermutation technique that combines two biological systems:
This creates a powerful tool for targeted in vivo diversification in E. coli, where adenine positions within the TR are selectively mutagenized while other bases remain largely unchanged.
The dgrec package provides tools to:
Source code: github.com/dbikard/dgrec
Documentation: dbikard.github.io/dgrec
Publication: Rochette et al., Diversity-generating retroelements for programmable targeted hypermutagenesis, Nature Biotechnology (2026)
dgrec requires Python 3.10 to 3.13 and installs with pip. The distribution is named dgrec-tools because dgrec was already taken on PyPI; the import name is still dgrec:
All dependencies, including ViennaRNA, are installed automatically — no conda environment is needed.
The LSTM model needs TensorFlow, which is an optional extra because it is large:
dgrec is used at two points in a DGRec experiment: beforehand, to choose a template region that will actually be mutagenized, and afterwards, to measure what the experiment produced. The package ships with a small example dataset, so the code below runs as written.
Before the experiment — score a candidate TR, from 0 (poor) to 1 (good):
0.84
A sequence that scores poorly can usually be rescued by recoding. The TR is itself non-coding, but it is read in the frame of the gene that carries the variable region (VR) it diversifies, so the substitutions are chosen to leave that protein unchanged. Making the same changes in the VR keeps the two homologous, which is what the recombination step relies on. See How to use.
After the experiment — call genotypes from the amplicon reads, deduplicated by UMI:
or, in Python, with the mutation profile plotted:
import os
from Bio import SeqIO
data_path = dgrec.get_example_data_dir() #the example dataset that ships with the package
ref_seq = str(next(SeqIO.parse(os.path.join(data_path, 'sacB_ref.fasta'), 'fasta')).seq)
gen_list = dgrec.get_genotypes(os.path.join(data_path, 'sacB_example.fastq.gz'), ref_seq,
ignore_pos=[0, 1, 2, 138, 139, 140, 141])
fig = dgrec.plot_mutations(gen_list, ref_seq, sample_name='sacB', TR_range=[50, 119])n reads: 1000
n_reads pass filter: 847
n_reads aligned: 824
Number of UMIs: 814
Median number of reads per UMI: 1.0
Number of genotypes: 123

The shaded region is the TR range, where DGRec mutagenesis is active. Note the enrichment of mutations at adenine positions within it — the hallmark DGRec signature.
Read the full walkthrough → for paired-end reads, the command-line options, TR recoding, and the LSTM model of the mutational profile. Every function is documented in the API reference.
If you use dgrec, please cite:
Rochette P, Lopez-Rodriguez E, Wen DJ, Régnier L, et al. Diversity-generating retroelements for programmable targeted hypermutagenesis. Nature Biotechnology (2026). doi:10.1038/s41587-026-03078-4
A separate paper describing the bioinformatics and sequence-design tools provided by this package is in preparation; once it is published, please cite both. A CITATION.cff file is included in the repository.