This module provides functionality to generate SVG chromatograms from ABIF trace files. It renders the four fluorescence channels with base calls in a visual format that resembles the output of DNA sequencing instruments. Command-line usage:
abichromatogram <trace_file.ab1> [options]
Options:
Example usage:
# Generate a chromatogram from a trace file abichromatogram input.ab1 -o output.svg # Generate a portable HTML report abichromatogram input.ab1 --html output.html # Generate a zoomed view of a specific region with downsampling abichromatogram input.ab1 -s 500 -e 1000 -d 5
Types
Channel = enum A = "A", C = "C", G = "G", T = "T"
- The four channels used in capillary electrophoresis Source Edit
HighlightRegion = object startPos*, endPos*: int ## Inclusive trace scan coordinates fill*: string ## SVG fill color; defaults to light yellow label*: string ## Optional label shown inside the highlight
- A highlighted trace scan region to draw behind the chromatogram. Source Edit
TraceData = object points*: seq[TraceDataPoint] ## Processed trace data points baseOrder*: string ## Order of bases in channels (e.g., "ACGT") peaks*: seq[int] ## Base call peak positions sequence*: string ## Called sequence traceLen*: int ## Total length of trace in data points baseColors*: Table[Channel, string] ## Color mapping for each nucleotide base
- Processed trace data ready for visualization Source Edit
TraceDataPoint = object position*: int ## X position (scan number) values*: Table[Channel, int] ## Intensity value for each channel (scaled 0-1000)
- A single data point in the trace with values for each channel Source Edit
Consts
DefaultHighlightFill = "#fff6a6"
- Source Edit
Procs
proc getTraceData(trace: ABIFTrace; debug: bool = false): TraceData {. ...raises: [KeyError, IOError, OSError], tags: [ReadIOEffect], forbids: [].}
-
Extracts and processes trace data from an ABIF file
This function processes both raw and analyzed data from the trace file, normalizes values for display, and maps the correct channels to bases.
Parameters: trace: The ABIFTrace object debug: Whether to print debug information
Returns: TraceData object containing processed data ready for visualization
Source Edit proc htmlEscape(s: string): string {....raises: [], tags: [], forbids: [].}
- Escapes text for safe inclusion in generated HTML. Source Edit
proc newHighlightRegion(startPos, endPos: int; fill: string = DefaultHighlightFill; label: string = ""): HighlightRegion {. ...raises: [], tags: [], forbids: [].}
- Convenience constructor for chromatogram highlight regions. Source Edit
proc renderChromatogramHtml(trace: ABIFTrace; data: TraceData; inputFile: string; width: int = 1200; height: int = 600; showBaseCalls: bool = true; startPos: int = 0; endPos: int = -1; downsample: int = 1; highlights: seq[HighlightRegion] = @[]): string {. ...raises: [KeyError, IOError, OSError], tags: [ReadIOEffect], forbids: [].}
- Renders a portable, dependency-free HTML viewer with embedded chromatogram data. The exported file is self-contained and supports scrolling, zooming, metadata inspection, and sequence-to-trace recentering in the browser. Source Edit
proc renderChromatogramSvg(data: TraceData; sampleName: string; width: int = 1200; height: int = 600; showBaseCalls: bool = true; startPos: int = 0; endPos: int = -1; downsample: int = 1; highlights: seq[HighlightRegion] = @[]): string {. ...gcsafe, raises: [Exception, KeyError], tags: [RootEffect], forbids: [].}
-
Renders the chromatogram as an in-memory SVG string (for embedding in reports, e.g. abiscreen's HTML evidence panels) rather than writing directly to a file. Returns "" if the requested range has no data.
Command-line usage:
abichromatogram <trace_file.ab1> [options]
Options:
-o, --output FILEOutput SVG file (default: chromatogram.svg)--html FILEOutput a portable HTML report with embedded SVG-w, --width WIDTHSVG width in pixels (default: 1200)--height HEIGHTSVG height in pixels (default: 600)-s, --start POSStart position (default: 0)-e, --end POSEnd position (default: whole trace)-d, --downsample FACTOR Downsample factor for visualization (default: 1)--highlight START-ENDHighlight a trace scan region; repeat or comma-separate--hide-basesHide base calls--debugShow debug information-h, --helpShow this help message and exit-v, --versionShow version information and exitExamples:
# Generate a basic chromatogram abichromatogram input.ab1 # Specify output file and downsample for smoother display abichromatogram input.ab1 -o output.svg -d 5 # Generate a portable HTML report abichromatogram input.ab1 --html output.html # Generate a zoomed view of a specific region with custom width abichromatogram input.ab1 -s 500 -e 1000 --width 1600 # Highlight one or more scan regions abichromatogram input.ab1 --highlight 540-620,780-830 # Generate a chromatogram without base call markers abichromatogram input.ab1 --hide-bases
Source Edit proc writeChromatogramHtml(trace: ABIFTrace; data: TraceData; inputFile, outFile: string; width: int = 1200; height: int = 600; showBaseCalls: bool = true; startPos: int = 0; endPos: int = -1; downsample: int = 1; highlights: seq[HighlightRegion] = @[]): bool {. ...raises: [KeyError, IOError, OSError], tags: [ReadIOEffect, WriteDirEffect, ReadDirEffect, WriteIOEffect], forbids: [].}
- Writes a portable HTML chromatogram report to outFile. Source Edit