Catch genome build conflicts, chr1 vs 1 naming drift, chrM vs MT traps, and contig order mismatches before your genomics pipeline silently emits empty files.
Bioinformatics tools fail quietly when chromosome names or genome builds disagree:
bedtools intersectandbcftools annotateoften exit with status0and write header-only empty outputs when one input useschr1(UCSC) and another uses1(Ensembl) orNC_000001.11(RefSeq).- Mitochondrial annotations on
chrMvanish againstMTreferences, and runningsed 's/^chr//'turnschrMinto an invalidMinstead ofMTwhile corrupting gene symbols that start withchr(such asCHRNA1). - Mixing
hg19(chrMlength16571) withGRCh37/b37(MTlength16569), orGRCh38(chr1length248956422) withT2T-CHM13v2.0(chr1length248387328), passes naive prefix renaming and produces shifted coordinates. - Lexicographic sort order (
chr1,chr10,chr2) breaksbedtools intersect -sortedandGATKsequence dictionary checks hours into an HPC job.
chrcheck inspects .bam, .sam, .vcf(.gz), .bed(.gz), .gtf/.gff3(.gz), .fa.fai, and .dict headers together in milliseconds without installing samtools, bcftools, pysam, or Java.
- Cross-Format Preflight in One Command: Compare binary
.bamheaders (BGZF-streamed without reading alignment records),.sam,.vcf/.vcf.gz,.bed/.narrowPeak/.broadPeak,.gtf/.gff3,.fa.fai,.dict, and.chrom.sizesin a single run. - Assembly Build Fingerprinting: Identifies
GRCh38/hg38,GRCh37/b37,hg19,T2T-CHM13v2.0/hs1,GRCm39/mm39, andGRCm38/mm10by contig length signatures and coordinate upper bounds, distinguishinghg19(chrM=16571) fromGRCh37(MT=16569). - Build-Safe Contig Mapping (
rename-map&--emit-chr-map): Generatesold<TAB>newTSV files ready forbcftools annotate --rename-chrs, and refuses to emit a rename map if inputs come from different genome assemblies (CrossMap/liftOverrequired). - Safe Column-1 BED/GTF/GFF3 Rewrite (
fix-bed): Converts column 1 and##sequence-regionheaders to match a target.bam,.fai,.dict,.vcf.gz, or style (ucsc,ensembl,refseq) without touching gene names or INFO attributes. - 12 Concrete Diagnostic Rules (
CHR-001–CHR-012): Flags build mismatches, mixed styles within a single file, coordinate overflows (pos > contig_len), 1-basedstart == endzero-length BED traps, sort-order drift, and missing##contigheaders. - Zero Runtime Dependencies: Pure Python 3.9+ standard library (
zlib,gzip,struct), running natively on Linux, macOS, and Windows.
Install directly from GitHub (or run without global install via pipx / uvx):
pip install "git+https://github.com/SuzumiyaHaruhi719/chrcheck.git"Run a preflight check across mixed pipeline inputs:
# 1. Check BAM, BED, and VCF compatibility before running downstream tools chrcheck alignments.bam capture_panel.bed clinvar.vcf.gz --emit-chr-map chr_map.tsv # 2. Rewrite BED column 1 to match the BAM reference dictionary safely chrcheck fix-bed capture_panel.bed --to alignments.bam -o capture_panel.ucsc.bed # 3. Re-check everything before submitting the cluster job chrcheck alignments.bam capture_panel.ucsc.bed
check is the default subcommand when passing file paths directly:
chrcheck reference.fa.fai sample.bam targets.bed variants.vcf.gz
Useful flags:
--format table|json|markdown: output format (tabledefault)--fail-on error|warning: exit1on errors only (error, default) or also on warnings (warning)--emit-chr-map path.tsv: write abcftools annotate --rename-chrsmapping from the last mismatched input to the first/reference input when assembly builds are compatible--sample-records 50000/--full: cap sampled records on huge plain/gz VCF/BED/GTF files (50000default) or scan every record--no-color: disable ANSI colors (also honorsNO_COLOR)
chrcheck inspect clinvar.vcf.gz chrcheck inspect alignments.bam --format json
Reads only the BGZF header blocks for .bam files, so inspecting a 50 GB WGS BAM completes in a few milliseconds.
chrcheck rename-map clinvar.vcf.gz --to alignments.bam -o chr_map.tsv bcftools annotate --rename-chrs chr_map.tsv -Oz -o clinvar.ucsc.vcf.gz clinvar.vcf.gz
If clinvar.vcf.gz is GRCh37 and alignments.bam is GRCh38, chrcheck stops with exit code 1 and advises liftover instead of generating a coordinate-corrupting rename map (override only if intentional with --force).
chrcheck fix-bed targets.bed --to alignments.bam -o targets.ucsc.bed chrcheck fix-bed genes.gtf --to ensembl -o genes.ensembl.gtf
Only column 1 (and GFF3 ##sequence-region directives) is remapped, including chrM <-> MT and RefSeq NC_* accessions, leaving gene symbols (CHRNA1, CHRNG) and attributes untouched.
Use chrcheck as a fast preflight stage in Nextflow, Snakemake, or GitHub Actions:
chrcheck --fail-on warning "${bam}" "${bed}" "${vcf}"
- name: Preflight reference compatibility run: | chrcheck --format markdown --fail-on error data/ref.fa.fai data/panel.bed data/variants.vcf.gz >> "$GITHUB_STEP_SUMMARY"
| Capability | chrcheck |
dpryan79/ChromosomeMappings |
vcfverifier |
vep-preflight |
picard CompareSAMs |
cut / sed one-liners |
|---|---|---|---|---|---|---|
Cross-format (BAM + VCF + BED + GTF + FAI + DICT) |
Yes | Static TSV tables only | VCF + FASTA only | Single VEP VCF only | SAM/BAM only | Manual per format |
Zero runtime deps (samtools/pysam/Java not needed) |
Pure Python stdlib | Manual curl/grep | Rust binary | Rust binary | Requires JVM + Picard | POSIX shell |
Reads 50 GB .bam header in milliseconds |
Yes (BGZF header only) | N/A | N/A | N/A | Reads full header | Fails on binary BAM |
Detects GRCh38 vs GRCh37 vs hg19 (16571 vs 16569) |
Yes | Static files per pair | Ref-base check only | Single-file headers | Length match only | No |
| Refuses rename map across incompatible builds | Yes (CHR-001/002) |
No | N/A | N/A | N/A | Silently corrupts coords |
Catches chrM/MT, order drift & start==end BED traps |
Yes (CHR-004/008/009) |
No | No | chr mix only |
Order only | sed turns chrM -> M |
| Code | Severity | Meaning |
|---|---|---|
CHR-001 |
ERROR |
Genome assembly build mismatch across inputs (GRCh38 vs GRCh37, CHM13v2.0, mm39 vs mm10) |
CHR-002 |
ERROR |
hg19 (chrM=16571) vs GRCh37/b37 (MT=16569) mitochondrial length mismatch |
CHR-003 |
ERROR |
Chromosome naming convention mismatch (UCSC chr1 vs Ensembl 1 vs RefSeq NC_*) |
CHR-004 |
ERROR |
Mitochondrial contig naming mismatch (chrM vs MT vs M) |
CHR-005 |
ERROR |
Mixed chromosome naming styles inside one file or between header and records |
CHR-006 |
ERROR |
Record coordinate exceeds contig length in header or reference dictionary |
CHR-007 |
ERROR |
Malformed interval (start < 0, start > end, or 1-based pos < 1) |
CHR-008 |
WARNING |
Zero-length BED intervals (start == end) suggesting unshifted 1-based coordinates |
CHR-009 |
WARNING |
Contig sort-order mismatch across inputs (chr1, chr10, chr2 vs karyotypic order) |
CHR-010 |
WARNING |
Data records reference contigs absent from the file's own header or reference input |
CHR-011 |
WARNING |
Sex chromosome or alt/decoy scaffold mismatch across inputs |
CHR-012 |
INFO |
All checked inputs are compatible |
Does chrcheck load an entire .bam or .vcf.gz into memory?
No. .bam inspection stops immediately after parsing the compressed BGZF header blocks and binary n_ref dictionary. Text and .gz inputs stream line by line up to --sample-records (default 50000, or all lines with --full).
Does chrcheck work on non-human organisms?
Yes. Built-in assembly signatures cover human (GRCh38/hg38, GRCh37/b37, hg19, T2T-CHM13v2.0) and mouse (GRCm39/mm39, GRCm38/mm10). For any other organism or custom reference, chrcheck leaves the assembly label as custom/unknown and still validates cross-file contig names, lengths, sort order, mitochondrial style, and coordinate bounds.
Why not just run sed 's/^chr//' input.bed?
Three reasons: sed turns chrM into M (not MT), alters feature names like CHRNA1 or chr22 in later columns if not column-anchored, and gives zero warning when your BED file is actually hg19 while your BAM is GRCh38.
- CRAM binary container header parsing with
@SQM5checksum comparison (#1) - SARIF 2.1.0 output (
--format sarif) for GitHub Code Scanning annotations (#2) - Built-in assembly signatures for zebrafish (
GRCz11), fruit fly (BDGP6/dm6), and C. elegans (WBcel235/ce11) (#3) - Binary
.bigWig/.bigBedchromosome B+ tree header inspection (#4)
Contributions are welcome. Read CONTRIBUTING.md and our Code of Conduct before opening a pull request.
Released under the MIT License.