feat(region): UCSC<->Ensembl chromosome-name aliasing for -r#78
Merged
Conversation
A `-r chr1:…` query against a file that names the contig `1` (or vice versa) silently returned zero rows — the classic UCSC-vs-Ensembl footgun. When the queried chromosome isn't a contig the file has but its counterpart is, vv now retries with the alias and notes the swap on stderr. Scoped deliberately: only HUMAN and MOUSE standard chromosomes are aliased — autosomes 1..22 (covers human 1-22 and mouse 1-19), X, Y, and the mitochondrion `chrM` <-> `MT` (never bare `M`). Scaffolds, patches and alt-contigs are never remapped, so a genuine typo (e.g. chr99) still errors/empties as before. `chrom_alias()` + a templated `resolve_chrom()`/`resolve_region_chroms()` resolve each window's chromosome against the file's own contig list, applied where each source knows its contigs: tabix (`tbx_seqnames`), BCF (`bcf_hdr_name2id`), BAM `--pileup` (`bam_name2id`), and LociSSD v4 (`rank_to_name`). Generic-Parquet and bigWig region paths (no cheap contig list) are a noted follow-up. New Ensembl-named fixture tiny.ens.bed.gz (contigs `1`, `MT`) + tests covering both directions, the chrM<->MT special case, and that non-standard names aren't remapped. Suite 370. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A
-r chr1:…query against a file that names the contig1(or vice versa) silently returned zero rows — the classic UCSC-vs-Ensembl naming footgun a bioinformatician hits constantly. vv now retries with the counterpart name when the queried chromosome isn't present but its alias is, noting the swap on stderr.Scoped deliberately (per the constraints): only human and mouse standard chromosomes are aliased — autosomes
1–22(covers human 1-22 and mouse 1-19),X,Y, and the mitochondrionchrM↔MT(never bareM). Scaffolds, patches, and alt-contigs are never remapped, so a genuine typo (e.g.chr99) still errors/empties exactly as before.chrom_alias()+ a templatedresolve_chrom()/resolve_region_chroms()resolve each region window's chromosome against the file's own contig list, applied where each source knows its contigs:.vcf.gz/.bed.gz/.gff.gz/.tsv.gz) viatbx_seqnamesbcf_hdr_name2id--pileupviabam_name2idrank_to_nameGeneric-Parquet and bigWig region paths (which don't carry a cheap contig list) are a noted follow-up.
Verification
tiny.ens.bed.gz(contigs1,MT).1↔chr1on LociSSD v4 / tabix VCF / BCF (equal row counts); thechrM→MTspecial case; the reversechr1→1; and that a non-standardchr99is not remapped (0 rows). Suite 370.🤖 Generated with Claude Code