Skip to content

Keep GRCh37 chrM apart from the rCRS MT (0.50.0) - #202

Merged
iskandr merged 1 commit into
mainfrom
fix/grch37-mitochondrion-200
Nov 7, 2026
Merged

iskandr merged 1 commit into
mainfrom
fix/grch37-mitochondrion-200

Conversation

@iskandr

@iskandr iskandr commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Closes #200. Bumps to 0.50.0, because GRCh37 contig matching changes.

Problem

orfdata.model._contig mapped M and chrM to MT whatever the build. Under GRCh37 these are different sequences:

  • hg19's chrM: NC_001807, 16,571 bp.
  • Ensembl's MT: the rCRS, NC_012920, 16,569 bp.

Their positions are offset (hg19 chrM:12995 is rCRS MT:12994). So a GRCh37 chrM record could be bound to Ensembl MT transcripts, merged with an MT record, or lifted through the rCRS chain.

Change

  • _contig(value, build, length=None):
    • Under GRCh37 (GRCh37, hg19, b37, NCBI37, with or without a .pN patch suffix), chrM/M stays chrM, and MT/chrMT stays MT.
    • A chrM whose known length is the rCRS's, 16,569 bp, is read as MT.
    • Other builds keep the old mapping.
  • build is required, so no caller can merge the two silently. Every caller passes the build it already has:
    • catalogue queries and _merge_key;
    • ORF binding and annotated-CDS placement;
    • the proteome and structure indexes;
    • RNAFeature.overlaps;
    • the RibORF native importer (pinned to mouse GRCm38→GRCm39, so its output is unchanged);
    • chain files.
  • Chain files:
    • Ensembl's GRCh37 files repeat their MT chain as chrM 16569. The header's contig size marks that copy as the rCRS, so it still coincides with the MT copy, as the existing comment expects.
    • An hg19 chrM (16,571 bp) chain is used only for chrM queries.
    • A GRCh37 chrM record with no chain of its own doesn't lift.
  • Released data: no bundled catalogue is GRCh37, so nothing changes in it. A GENCODE GRCh37 catalogue, which calls the rCRS chrM, should name it MT. The CHANGELOG says so.
  • Consistency: this matches varcode 11.8.0 (Fix MAF loading and stop renaming hg19 chrM to rCRS MT (11.8.0) varcode#706, for hg19 chrM is renamed to rCRS MT without converting positions (load_vcf, Variant, CLI) varcode#707), which keeps hg19's chrM apart from MT in its own ORF matching.

Verification

  • New tests/test_grch37_mitochondrion.py: both tests fail on main and pass here.
    • Chains: with Ensembl's MT and chrM 16569 rCRS chains plus a synthetic hg19 chrM 16571 chain:
      • MT:12995 maps to MT:12995.
      • chrM:12995 maps to MT:12993, through the hg19 chain only.
      • On main, both queries are ambiguous and return None.
      • A GRCh38 chrM still maps as MT.
    • Catalogues:
      • Under GRCh37, MT/chrMT queries find only the rCRS record, and chrM/M only the hg19 one.
      • Merging catalogues keeps them as two ORFs; main merged them into one.
  • Checked against the real Ensembl chains: GRCh37_to_GRCh38.chain.gz and GRCh38_to_GRCh37.chain.gz (pinned SHA-256s) contain exactly MT 16569 and chrM 16569 mitochondrial chains.
  • Checks:
    • Full suite: 1,519 passed, 4 skipped.
    • ./lint.sh passes, and mkdocs build --strict is clean.
    • Neither varcode nor isovar imports the private _contig.

https://claude.ai/code/session_01JHJhwgzAgwTefwxNLB1ztR

Under GRCh37, hg19's chrM (NC_001807, 16,571 bp) is not the rCRS that
Ensembl names MT (16,569 bp), and its positions are offset from it.
_contig now takes the build and, under GRCh37, keeps chrM/M distinct from
MT/chrMT unless a known length is the rCRS's (Ensembl's chain files repeat
the rCRS chain as chrM with that length). Every caller passes its build.

Closes #200.

Claude-Session: https://claude.ai/code/session_01JHJhwgzAgwTefwxNLB1ztR
@iskandr
iskandr merged commit 0feda29 into main Nov 7, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_contig maps chrM/M to MT regardless of build; under GRCh37 hg19's chrM is not the rCRS

1 participant