Skip to main content

Pypi Releases Downloads CI Python

sanger

A lightweight toolkit for Sanger sequencing data: chromatogram visualization, alignment & mutation calling, quality control, base-calling, trimming, assembly and export — usable as a CLI, a Python library, or an MCP server for LLM agents.

Quick start

pip install sanger
sanger mut -q read.ab1 -s ref.fa -o out --plot
from sanger import Chromatogram, parse_fasta

cg = Chromatogram.from_abi("./data/B5-M13R_B07.ab1")
print(cg.length, cg.mean_quality, cg.gc_percent)   # 1141 50.2 52.0
ref = parse_fasta("./data/ref.fa")
print(cg.qc())                                    # QC metrics (CRL, SNR)
print(cg.to_vcf(ref))                             # variant calling -> VCF
cg.plot(region=(55, 90))                          # render a region

Examples

The gallery below is produced from the bundled real ABI sample (data/B5-M13R_B07.ab1 vs data/ref.fa) by python -m scripts.make_readme_examples.

Mutation calling — the SNP T61A is highlighted and annotated.

Mutation calling

Quality control — per-base Phred quality, CRL and Mott trimming.

Quality profile

Side-by-side panels — chromatogram + GC% + quality on a shared axis.

Side-by-side

Feature overlay — primers, amplicon and SNPs on the trace.

Feature overlay

Re-called bases — mixed/heterozygous sites are marked (M/W/K).

Re-called bases

Assembly — pileup depth and consensus against a reference.

Assembly

Installation

The default install pulls only numpy, click and rich-click — no C compiler and no plotting library required. Parsing, QC, alignment (a bundled Cython Smith-Waterman with a NumPy fallback), analysis and export all work out of the box.

pip install sanger

Optional extras:

pip install "sanger[plot]"     # matplotlib -> chromatogram figures
pip install "sanger[viewer]"   # DNA Features Viewer integration
pip install "sanger[agent]"    # MCP server for LLM agents
pip install "sanger[all]"      # everything

The bundled Cython Smith-Waterman accelerator (sanger._swalign, self-contained, no ssw dependency) is compiled automatically when a C compiler is present at build time; otherwise the NumPy fallback is used.

From source:

git clone git@github.com:y9c/sanger.git
cd sanger
make init       # install dependencies
make test       # run the test-suite

Command-line interface

Built on rich-click, with themed command groups (sanger --help):

sanger mut            mutation calling & reporting
sanger qc             per-read quality-control metrics
sanger track          split / join / slice chromatogram trace files
sanger edit           trim, strip primers, reverse-complement
sanger basecall       re-call bases from raw four-channel traces
sanger assemble       reference-guided pileup & consensus
sanger analyze        sequence biology (translate, motifs, restriction)
sanger export         FASTA / VCF / JSON / batch summary
sanger plot           chromatogram rendering (+ features / DNA viewer)

Examples:

sanger mut -q read.ab1 -s ref.fa -o out --plot        # mutation report + figure
sanger qc r1.ab1 r2.ab1                               # QC table
sanger track split read.ab1 -c 20,40 -f tsv           # split traces
sanger edit trim read.ab1 -c 0.05 -o out              # Mott quality trim
sanger edit strip-primers read.ab1 -f AAAA -r CCCA    # primer removal
sanger basecall call read.ab1 -r 0.45                 # re-call bases
sanger basecall hetero read.ab1                       # mixed/heterozygous sites
sanger assemble consensus a.ab1 b.ab1 -r ref.fa       # reference-guided consensus
sanger analyze rest read.ab1                          # restriction sites
sanger analyze translate read.ab1 -f 1                # protein translation
sanger export vcf -q read.ab1 -s ref.fa               # VCF of variants
sanger export batch *.ab1 -o out -f csv               # batch QC table
sanger plot dnaviewer read.ab1 --start 50 --end 100   # with DNA Features Viewer

Python API

The high-level Chromatogram object is the easiest way to work with the toolkit; the low-level modules remain available for custom work.

from sanger import Chromatogram, parse_fasta

cg = Chromatogram.from_abi("./data/B5-M13R_B07.ab1")
ref = parse_fasta("./data/ref.fa")
Common operations

Mutation calling & quality filtering

from sanger.quality import QualityFilter

snps = cg.call_mutations(ref)
confident = QualityFilter(min_base_qual=20, min_local_qual=20).filter(snps)
print([f"{s.ref_base}{s.ref_pos}{s.cf_base}" for s in confident])

QC metrics (incl. continuous read length)

m = cg.qc()
print(m["mean_qual"], m["trim_start"], m["trim_end"], m["crl"], m["snr"])

Re-call bases from raw traces + mixed/heterozygous sites

res = cg.basecall()
print(res.sequence)
for pos, major, minor, frac in res.heterozygotes(min_ratio=0.2):
    print(pos, major, minor, frac)

Trim / reverse-complement / orientation

trimmed = cg.trim().trim_leading_ns()     # Mott trim then drop leading Ns
rc      = cg.reverse_complement()
ori     = cg.detect_orientation(ref)      # +1 forward, -1 reverse-complement

Sequence-level analysis

print(cg.analyze("translate", frame=1))            # protein translation
print(cg.analyze("restriction"))                    # {'EcoRI': [27], ...}
print(cg.analyze("motif", motif="AATT"))            # motif positions

Export

print(cg.to_fasta())
print(cg.to_vcf(ref))
cg.export("out")                                    # write FASTA to disk

Feature overlay (for external tools)

from sanger import ChromatogramFeature
from sanger.features import plot_features

feat = ChromatogramFeature(start=90, end=130, strand=+1, label="primer F")
fig, ax = cg.plot(region=(80, 140))
plot_features(cg.to_record, ax, features=[feat])

Side-by-side with another tool's output (shared x-axis)

from sanger.composite import side_by_side

def my_panel(ax, trace_x, peaks, seq, record, start=None):
    ax.bar(range(len(seq)), [1.0] * len(seq), color="0.66")
    ax.set_ylabel("my tool signal")

fig, (ax_chrom, ax_panel) = side_by_side(cg.to_record, my_panel, region=(10, 40))

Consensus / assembly from many reads

from sanger import parse_abi
from sanger.assembly import pileup, consensus

reads = [parse_abi(f) for f in ["a.ab1", "b.ab1", "c.ab1"]]
table = pileup(reads, ref, quality_threshold=20)
print(consensus(table))

Plot together with DNA Features Viewer (needs sanger[viewer])

from sanger import ChromatogramFeature
from sanger.dnalink import plot_combined

feats = [ChromatogramFeature(start=90, end=130, strand=+1, label="primer F")]
fig, (ax_feat, ax_chrom) = plot_combined(cg.to_record, features=feats, region=(55, 90))

Chromatogram object

A terse, idiomatic workflow in one object:

from sanger import Chromatogram

cg = Chromatogram.from_abi("./data/B5-M13R_B07.ab1")
cg.length, cg.mean_quality, cg.gc_percent, cg.channels   # 1141 50.2 52.0 GATC
cg.qc()                            # QC metrics (CRL, SNR)
cg.basecall()                      # re-call bases from raw traces
cg.call_mutations(ref)             # variant calling
cg.trim().trim_leading_ns()        # quality trimming
cg.reverse_complement()            # reverse-strand view
cg.analyze("restriction")          # restriction-site scan
cg.plot(region=(55, 90))           # render a region
cg.to_fasta(), cg.to_vcf(ref)      # export
cg.export("out")                   # write to disk

Agent / MCP

sanger ships a Model Context Protocol server so LLM agents and MCP clients can call the toolkit as tools:

pip install "sanger[agent]"     # adds mcp>=2
sanger-mcp                        # run the MCP server over stdio
python -m sanger.mcp_server       # identical
Tool Purpose
read_chromatogram(path) parse an ABI → summary (length, GC%, quality, CRL)
qc_metrics(path) full per-read QC metrics (incl. CRL, signal, SNR)
call_mutations(query ab1, subject fa) variants vs a reference (SNPs/indels)
re_call_bases(path) re-call bases from raw traces + heterozygotes
analyze_sequence(path, kind) translate / motifs / restriction / GC
trim_read(path, mode) quality-trim a read
export_sequence(path, outdir) write FASTA or VCF
plot_chromatogram(path, out, start, end) render a chromatogram PNG

Register it in an MCP client's config, e.g.:

{ "mcpServers": { "sanger": { "command": "sanger-mcp" } } }

ChangeLog

  • Replace the external ssw aligner with a bundled Cython Smith-Waterman (+ NumPy fallback) — no external alignment dependency.
  • Reverse-complement the chromatogram file (inspired by Snapgene).
  • Add per-base quality filtering, continuous read length (CRL), signal/SNR QC.
  • Add base-calling from raw four-channel traces + heterozygote (mixed-base) calling.
  • Add feature overlay API and DNA Features Viewer integration.
  • Add split / join / slice trace operations with provenance (offset).
  • Add reference-guided pileup & consensus (assembly module).
  • Add FASTA / VCF / JSON / batch export.
  • Fix false-positive mutations from lowercase reference bases (case-insensitive).
  • Build the CLI with rich-click (themed groups, short options, --version).

TODO

  • call mutation by alignment and plot Chromatogram graphic
  • add a doc
  • change x-axis by peak location
  • fix bug that chromatogram switches position after trim
  • wrap as a CLI app
  • return quality score in output (quality module + report)
  • fix selected base not being centred (center_region)
  • fix plot_chromatograph rendering bug (full-region bounds, channels)
  • add projection/assembly (assembly module)
  • preserve trimmed-origin positions when slicing/joining (offset provenance)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sanger-0.1.3.tar.gz (133.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

sanger-0.1.3-cp314-cp314-musllinux_1_2_x86_64.whl (245.1 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

sanger-0.1.3-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (245.2 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

sanger-0.1.3-cp313-cp313-musllinux_1_2_x86_64.whl (246.0 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

sanger-0.1.3-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (246.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

sanger-0.1.3-cp312-cp312-musllinux_1_2_x86_64.whl (249.3 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

sanger-0.1.3-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (249.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

sanger-0.1.3-cp311-cp311-musllinux_1_2_x86_64.whl (242.2 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

sanger-0.1.3-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (242.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

sanger-0.1.3-cp310-cp310-musllinux_1_2_x86_64.whl (237.1 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

sanger-0.1.3-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (237.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

File details

Details for the file sanger-0.1.3.tar.gz.

File metadata

  • Download URL: sanger-0.1.3.tar.gz
  • Upload date:
  • Size: 133.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for sanger-0.1.3.tar.gz
Algorithm Hash digest
SHA256 83a9734d93ca0aef4c5ecb6538563b39be5d9696d2bb39e4541bae3d3f34899f
MD5 68fbd78b2d4e45ac4fee3837dc374c97
BLAKE2b-256 6ea76920616c42477d8867c3fb37345f5639e8753549d6eadbfe44789a1c1a3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanger-0.1.3.tar.gz:

Publisher: pypi.yml on y9c/sanger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sanger-0.1.3-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sanger-0.1.3-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a35f22c7d5a78b3733e314b08e81f30e18d0fbb0384ff918500e6a8e9ac83868
MD5 9c5825b89071bcad013c0d54bd2d3000
BLAKE2b-256 e01663faa56ade3168f5918849b310e32b53f779633b40d6b8561f2f14dda2f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanger-0.1.3-cp314-cp314-musllinux_1_2_x86_64.whl:

Publisher: pypi.yml on y9c/sanger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sanger-0.1.3-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for sanger-0.1.3-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 3ce59f9b668a6a43b87e059ae46ef1a9eb65e0887b3f810c13bf7a1750b0fa0e
MD5 e9cdd5bf90fcd8b8743597f51241a4c9
BLAKE2b-256 869c67b8d59b65ca13ee63e002a01784e0dec7b4fde8da3949e0a26148a7fc1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanger-0.1.3-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: pypi.yml on y9c/sanger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sanger-0.1.3-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sanger-0.1.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e7c52e38093313c74271bb82599412549fae0baa0aef4e0a4b9f037d3a1bab65
MD5 455ebd7f33400444d44f995ebf40db8c
BLAKE2b-256 bf6a25542b980050040d70c7291c1e0e3675fc3a2ae4ca1d66f85922b26428f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanger-0.1.3-cp313-cp313-musllinux_1_2_x86_64.whl:

Publisher: pypi.yml on y9c/sanger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sanger-0.1.3-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for sanger-0.1.3-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 dcc68a8779cfbf2f3e0c8f96d527769758f1ee0d9547bcf4e54d285d353b61b7
MD5 47f327b6e3631bfbc3dbf3311705ae52
BLAKE2b-256 258c200396359a383a55d424ea90e9ca0128a2972343b6acb8a4d017bd563aec

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanger-0.1.3-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: pypi.yml on y9c/sanger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sanger-0.1.3-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sanger-0.1.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c6eecd5b02763a3101c22fe102a31e6b3c5ab74b5cbc094b6f860ea08f8f3e33
MD5 fae832bc38bf96118104ad4c735aeeb9
BLAKE2b-256 87fd554f914a4c318b8717ebd4760a90cd63bc3b738b2945e41ea7e039202fd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanger-0.1.3-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: pypi.yml on y9c/sanger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sanger-0.1.3-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for sanger-0.1.3-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 0bcd1b0a0346f1ef263de81f9f2791d0d2670e85e527ec57bfc0307e3de6f398
MD5 0de784f60057ec47b99b82f4ef1f3be0
BLAKE2b-256 100c21c0ea37ad8eeb327ab060ebbbacf1d04f76ed6032b1ded81d8208dd67df

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanger-0.1.3-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: pypi.yml on y9c/sanger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sanger-0.1.3-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sanger-0.1.3-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2309b0e77025f678c948c38e15d3d6376117dd3b73a1d055765d68a54732869f
MD5 10f37ea8d3df356f16db74188f2289bf
BLAKE2b-256 628891910d4c58612e5ffd330b5a5c8322e9c418acaec04f23a6545d6a10bad6

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanger-0.1.3-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: pypi.yml on y9c/sanger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sanger-0.1.3-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for sanger-0.1.3-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 4d491dc3204090b48e5943647f961cde801c30f9ced2eb6a44e41c771efac68c
MD5 afae28e21e682fec8051f1b36aa05584
BLAKE2b-256 941fdd0c4deef9a9d841470bf1c043a2dfd9e608e63420d97f3472b99f6629c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanger-0.1.3-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: pypi.yml on y9c/sanger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sanger-0.1.3-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sanger-0.1.3-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8d846e6f11d16c7342f394dae83978cbfe8e9579bfb586d7cc42e4f4e3c76b72
MD5 e84466ea7a43aa3f55d01e4f9887fbca
BLAKE2b-256 308b578aa28bc39c494f8c7dabaaca94ead23f4151270aae2df19f8486105e61

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanger-0.1.3-cp310-cp310-musllinux_1_2_x86_64.whl:

Publisher: pypi.yml on y9c/sanger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sanger-0.1.3-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for sanger-0.1.3-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 bce6c95a0aaa1179ddb45a0839bdeb6dcdd64d76d713c9d614f4f39fc16b1acf
MD5 dc856acbe1519bbea9210fb121169abf
BLAKE2b-256 629dd647e8ed30db6c3b33516bc2f803dcc5b745dab979ee8c9a044a9e60de26

See more details on using hashes here.

Provenance

The following attestation bundles were made for sanger-0.1.3-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: pypi.yml on y9c/sanger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.5

21 files

0.1.4

16 files

This release

0.1.3 This release

11 files

0.1.2

9 files

0.1.1

1 file

0.1.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page