dgrec

A Python package for designing and analyzing DGRec (Diversity Generating Retroelement + Recombineering) experiments

Overview

DGRec is an in vivo hypermutation technique that combines two biological systems:

  • DGR (Diversity Generating Retroelement): the DGR reverse transcriptase (bRT) and its accessory protein Avd reverse-transcribe the template region (TR), a segment of a small non-coding RNA called the dgrRNA, making errors predominantly at adenine positions.
  • Recombineering (CspRecT + mutL*): the single-strand annealing protein CspRecT integrates the mutagenic cDNA into the variable region (VR) of a target gene, while mutL* prevents mismatch repair from correcting the mutations.

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:

  • Design TR sequences: score a candidate TR from the predicted folding of its dgrRNA, and recode a poorly mutagenic one using codon substitutions that leave the protein encoded by the target gene unchanged
  • Predict the diversity a TR will generate: an LSTM model of the position- and context-dependent error profile of the reverse transcriptase, used to simulate the VR sequences reachable from a given TR
  • Call genotypes from amplicon sequencing data (single-end or paired-end), with UMI-based deduplication to correct PCR and sequencing errors
  • Visualize mutation profiles at nucleotide and amino acid resolution

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)

Install

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:

pip install dgrec-tools

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:

pip install "dgrec-tools[lstm]"

Quick start

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):

import dgrec

dgrec.tr_score('AAATGATCGCCAAATCTGAACAGGAAATTGGCAAAGCAACCGCTAAATACTTTTTCTACTCAAACATTAT')
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:

dgrec genotypes reads.fastq.gz reference.fasta -o genotypes.csv

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.

Citation

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.