CoveragePlotter can be used to generate the coverage figure for genomic regions contained in BAM files and to visualize per-base read coverage across a genomic region of interest. What's required is a bam file with mapped reads aligned to its reference genome, and a gff3 file, which is optional but recommended if you are interested in checking based on gene ID rather than chromosome start and end positions. pysam is the Python module used to read and extract the sorted BAM files directly. Coverage generated from sequencing data has a noisy and irregular shape, due to local fluctuations in read depth; CoveragePlotter.py therefore offers two alternative smoothing methods, a sliding-window moving average and a Gaussian-kernel (KDE-style) smoothing, so that users can select and justify whichever alternative best preserves real biological structure in their own data rather than relying on a single fixed approach. Multiple result files can be combined into a single stacked figure for direct comparison, or split into individual figures automatically once a configurable sample-count threshold is exceeded, or forced either way regardless of sample count.
-
Python3
-
pysam
-
matplotlib
python3 CoveragePlotter.py
[--bam <BAM_FILE> [<BAM_FILE2> ...] | --bamdir <FOLDER>]
[--chr <CHR> --start <START> --end <END> | --gff <GFF3> --gene <GENE_ID>]
--out <FIGURE_FILE>
[optional flags]
Simplest case, one BAM file, an exact region:
python3 CoveragePlotter.py --bam sample1.bam --chr chr1 --start 1000 --end 5000 --out coverage.pngLook up a gene by ID instead of typing coordinates (also draws the exon/intron model):
python3 CoveragePlotter.py --bam sample1.bam --gff genome.gff3 --gene AT1G01010 --out coverage.pngSeveral samples at once, with smoothing
python3 CoveragePlotter.py --bam sample1.bam sample2.bam sample3.bam --gff genome.gff3 --gene AT1G01010 --smooth 15 --out coverage.pngA whole folder of BAM files instead of listing them:
python3 CoveragePlotter.py --bamdir bam_files/ --gff genome.gff3 --gene AT1G01010 --out coverage.pngReads (choose one)
| Flag | Meaning |
|---|---|
--bam <FILE> [<FILE2> ...] |
one or more BAM files; each gets its own coverage panel |
--bamdir <FOLDER> |
every .bam file in this folder, instead of listing them with --bam |
Region (choose one)
| Flag | Meaning |
|---|---|
--chr <CHR> + --start <N> + --end <N> |
exact region (all three required together) |
--gff <FILE> + --gene <ID> |
look up the gene's region in the GFF3 (both required together); also draws the exon/intron model |
Output
| Flag | Meaning |
|---|---|
--out <FILE> |
output figure path, e.g. coverage.png; the folder is created automatically if it doesn't exist yet |
Two alternative ways to reduce noise in the coverage line. Only one is ever applied, if you give both, --kde wins, and the script prints a note saying so.
| Flag | Meaning | Default |
|---|---|---|
--smooth <N> |
moving-average smoothing over N bases | off |
--kde <N> |
Gaussian-kernel (KDE-style) smoothing, bandwidth N smoother, no hard window edge | off |
--show-raw |
also draw the raw, unsmoothed coverage as a faint line behind the smoothed one | off |
Controls whether all samples go into one figure or one figure each. Decision order: --split → --combine → sample count vs. --group-size. The script always prints which rule it used and why.
| Flag | Meaning | Default |
|---|---|---|
--split |
always save one figure per BAM file | - |
--combine |
always save one combined figure | - |
--group-size <N> |
if neither above is given: ≤N samples → combined, >N samples → auto-split | 4 |
| Flag | Meaning | Default |
|---|---|---|
--padding <N> |
extra bases shown around a --gene lookup |
200 |
--minqual <N> |
minimum mapping quality of reads to count | 0 |