Skill Tracer
Skills › Scientific Agent Skills › genomic-coordinates

genomic-coordinates

skill · 243 lines · MIT · skills/genomic-coordinates/SKILL.md

The facts

Its description

Converts genomic intervals between coordinate conventions, normalises and compares variant representations, and detects assembly or contig-naming mismatches before they corrupt an analysis. Used whenever coordinates cross a format, tool, or assembly boundary - converting between BED, GFF/GTF, VCF, SAM/BAM, WIG, PSL, genePred, Picard interval_list, or region strings; reconciling 0-based half-open with 1-based inclusive; left-aligning or trimming indels; checking whether two variant records describe the same change; mapping genomic to transcript, CDS, or protein positions; auditing a BED/GTF/VCF for convention violations; or diagnosing GRCh37 vs hg19 vs GRCh38 vs T2T, chr-prefix, and liftover problems. Triggers include "off by one", "0-based", "1-based", "half-open", "coordinate system", "left-align", "normalize variant", "bcftools norm", "chr prefix", "wrong genome build", "liftover", "REF mismatch", and "HGVS".

The description the agent reads to decide when to use it.

From its settingsline 3

Tools it may use, or may not

allowed-tools: Read Write Edit Bash

Tools it may use while it runs without asking you first.

From its settingsline 6

Runs scripts

python3 convert_coords.py, python3 normalize_variant.py (first 5 of 12 lines)

Scripts the text names. Found by matching words, so treat them as pointers.

Found by matching wordsline 63 line 64 line 65 line 66 line 99

Files it mentions

references/format-conventions.md, references/variant-representation.md, references/reference-builds.md, references/transcript-coordinates.md (first 5 of 8 lines)

Files the text names, such as ones to read or write. Found by matching words, so treat them as pointers.

Found by matching wordsline 57 line 127 line 155 line 193 line 218

Licence

MIT, from the skill file

The terms its author shares it under, which let it be shown here.

From its settingsline 4 licence text

Other settings

compatibility: Requires Python 3.11+. Scripts use only the standard library - no third-party packages and no network access. Variant normalisation needs an uncompressed reference FASTA with exact contig names; .fai enables indexed access. Without .fai the entire FASTA is loaded into memory. metadata: version: "1.3" last-reviewed: "2026-10-01" skill-author: K-Dense Inc.

More settings at the top of the file, shown as written.

From its settingsline 5 line 7
Other files in this skill (9) Close

The text

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1---
2name: genomic-coordinates
3description: Converts genomic intervals between coordinate conventions, normalises and compares variant representations, and detects assembly or contig-naming mismatches before they corrupt an analysis. Used whenever coordinates cross a format, tool, or assembly boundary - converting between BED, GFF/GTF, VCF, SAM/BAM, WIG, PSL, genePred, Picard interval_list, or region strings; reconciling 0-based half-open with 1-based inclusive; left-aligning or trimming indels; checking whether two variant records describe the same change; mapping genomic to transcript, CDS, or protein positions; auditing a BED/GTF/VCF for convention violations; or diagnosing GRCh37 vs hg19 vs GRCh38 vs T2T, chr-prefix, and liftover problems. Triggers include "off by one", "0-based", "1-based", "half-open", "coordinate system", "left-align", "normalize variant", "bcftools norm", "chr prefix", "wrong genome build", "liftover", "REF mismatch", and "HGVS".
4license: MIT
5compatibility: Requires Python 3.11+. Scripts use only the standard library - no third-party packages and no network access. Variant normalisation needs an uncompressed reference FASTA with exact contig names; .fai enables indexed access. Without .fai the entire FASTA is loaded into memory.
6allowed-tools: Read Write Edit Bash
7metadata:
8 version: "1.3"
9 last-reviewed: "2026-10-01"
10 skill-author: K-Dense Inc.
11---
13# Genomic Coordinates

Genomic Coordinates

Raw lines 1 to 14
15## When to use
17Any time a coordinate crosses a boundary: between two file formats, between two
18tools, between two assemblies, or between the genome and a transcript.

When to use

Any time a coordinate crosses a boundary: between two file formats, between two tools, between two assemblies, or between the genome and a transcript.

Raw lines 15 to 19
20## The rule
22**A coordinate is three facts, not one: the number, the convention it is written
23in, and the assembly it was measured against.** Carry all three or the number is
24not interpretable.
26Coordinate errors are the quietest class of bug in genomics. An off-by-one BED
27file parses, sorts, and intersects without complaint. A GRCh37 VCF joined against
28a GRCh38 annotation returns rows. A right-shifted indel simply fails to match its
29entry in ClinVar, and the result is a variant reported as novel. Nothing raises
30an error; the answer is just wrong, and it is wrong in a direction that looks
31plausible.
33So: convert with the table, not from memory, and verify against the reference
34whenever a reference is available.

The rule

A coordinate is three facts, not one: the number, the convention it is written in, and the assembly it was measured against. Carry all three or the number is not interpretable.

Coordinate errors are the quietest class of bug in genomics. An off-by-one BED file parses, sorts, and intersects without complaint. A GRCh37 VCF joined against a GRCh38 annotation returns rows. A right-shifted indel simply fails to match its entry in ClinVar, and the result is a variant reported as novel. Nothing raises an error; the answer is just wrong, and it is wrong in a direction that looks plausible.

So: convert with the table, not from memory, and verify against the reference whenever a reference is available.

Raw lines 20 to 35
36## The two conversions
38```
391-based inclusive -> 0-based half-open : start - 1, end
400-based half-open -> 1-based inclusive : start + 1, end
41```
43These formulas apply to nonempty spans on the same reference and strand. They do
44not encode insertions, circular wraparound, liftover, or transcript mapping.

The two conversions

1-based inclusive  ->  0-based half-open :  start - 1,  end
0-based half-open  ->  1-based inclusive :  start + 1,  end

These formulas apply to nonempty spans on the same reference and strand. They do not encode insertions, circular wraparound, liftover, or transcript mapping.

Raw lines 36 to 45
46## Which format is which
48| 0-based, half-open | 1-based, inclusive |
49| --- | --- |
50| BED, bedGraph, bigWig, narrowPeak | GFF3, GTF, VCF |
51| BAM (binary POS), BCF (binary POS) | SAM text POS, CRAM absolute alignment start |
52| PSL, genePred, refFlat | WIG, Picard interval_list |
53| MAF (UCSC multiple alignment) | MAF (TCGA mutation annotation) |
54| PyRanges, pybedtools | GRanges/IRanges, samtools & UCSC & Ensembl region strings |
56Both "MAF" formats exist, they mean different things, and they disagree. UCSC
57serves 0-based files through a 1-based browser box. `references/format-conventions.md`
58has the full table with per-format detail.
60```bash
61cd skills/genomic-coordinates/scripts
63python3 convert_coords.py --list # the table
64python3 convert_coords.py --from bed --to gff chr1 999 1000
65python3 convert_coords.py --from ucsc --to bed "chr7:5,530,601-5,530,625"
66python3 convert_coords.py --from granges --to pyranges --input regions.tsv
67```
69```
70contig input output length status detail
71chr7 chr7:5530601-5530625 5530600-5530625 25 ok
72```
74Zero-length BED features (`chromStart == chromEnd`, a legal insertion point) are
75reported as `unrepresentable` for an inclusive target because the converter lacks
76feature semantics. GFF3 can encode insertion sites with equal endpoints and a
77feature type; that is different from an ordinary single-base interval. Exit code
78is 1 for invalid or unrepresentable output; valid zero-length half-open output
79exits 0. Output is a diagnostic TSV/JSON table, not a rewritten GFF/VCF.
81`--input` parses BED/bedGraph, GFF/GTF, literal-allele VCF REF spans, explicit
82region strings, and three-column GRanges/PyRanges/Python TSVs. Other table rows
83are conventions only: extract an interval with a native parser and pass a triple.
84All bundled text readers expect uncompressed files.

Which format is which

0-based, half-open1-based, inclusive
BED, bedGraph, bigWig, narrowPeakGFF3, GTF, VCF
BAM (binary POS), BCF (binary POS)SAM text POS, CRAM absolute alignment start
PSL, genePred, refFlatWIG, Picard interval_list
MAF (UCSC multiple alignment)MAF (TCGA mutation annotation)
PyRanges, pybedtoolsGRanges/IRanges, samtools & UCSC & Ensembl region strings

Both "MAF" formats exist, they mean different things, and they disagree. UCSC serves 0-based files through a 1-based browser box. references/format-conventions.md has the full table with per-format detail.

cd skills/genomic-coordinates/scripts

python3 convert_coords.py --list                          # the table
python3 convert_coords.py --from bed --to gff chr1 999 1000
python3 convert_coords.py --from ucsc --to bed "chr7:5,530,601-5,530,625"
python3 convert_coords.py --from granges --to pyranges --input regions.tsv
contig  input                 output           length  status  detail
chr7    chr7:5530601-5530625  5530600-5530625  25      ok

Zero-length BED features (chromStart == chromEnd, a legal insertion point) are reported as unrepresentable for an inclusive target because the converter lacks feature semantics. GFF3 can encode insertion sites with equal endpoints and a feature type; that is different from an ordinary single-base interval. Exit code is 1 for invalid or unrepresentable output; valid zero-length half-open output exits 0. Output is a diagnostic TSV/JSON table, not a rewritten GFF/VCF.

--input parses BED/bedGraph, GFF/GTF, literal-allele VCF REF spans, explicit region strings, and three-column GRanges/PyRanges/Python TSVs. Other table rows are conventions only: extract an interval with a native parser and pass a triple. All bundled text readers expect uncompressed files.

Raw lines 46 to 85
Runs code python3 convert_coords.py :63
86## Variants are not intervals
88For a simple VCF indel, `POS` normally identifies the unchanged padding base
89before the event. At contig position 1 the padding can follow the event. Complex
90substitutions need not have an unchanged anchor. And the same change can be written many ways:
91`chr1:7:CAC:C`, `chr1:3:CAC:C` and `chr1:2:GCA:G` are one deletion. Joining,
92deduplicating, or looking up variants before normalising loses real matches
93silently, and it loses them preferentially in repeats, where indels concentrate.
95Normalise — trim to parsimony, then left-align against the reference — before any
96comparison:
98```bash
99python3 normalize_variant.py --fasta ref.fa chr1 7 CAC C
100python3 normalize_variant.py --fasta ref.fa --split --input cohort.vcf
101python3 normalize_variant.py --fasta ref.fa --compare chr1:7:CAC:C chr1:2:GCA:G
102```
104```
105input normalized type pos_shift ref_check changed
106chr1:7:CAC:C chr1:2:GCA:G deletion 5 ok yes
107```
109Literal alleles are checked against the FASTA using exact contig names. A
110`MISMATCH` can indicate an assembly, sequence, strand, or coordinate error; stop
111and investigate with `check_contigs.py` and sequence provenance. The helper
112rejects unsplit ALT lists: use `--split` for independently normalized allele keys.
113Its TSV discards genotypes and annotations; use `bcftools norm` for production
114VCF rewriting. Symbolic/breakend/missing/spanning-deletion alleles are passed
115through as `skipped`, without REF or structural validation.
117The default left-shift window is 1,000 bp. If it prevents completion, the helper
118returns `incomplete`, exits 1, and refuses an equivalence verdict. Increase
119`--window` and rerun. Matching normalized keys tests individual literal alleles,
120not haplotype equivalence across multiple records.
122[HGVS applies the 3'-most rule](https://hgvs-nomenclature.org/stable/recommendations/general/)
123to the reference sequence being described. For transcript `c.`/`n.` notation,
124this means increasing genomic coordinates on a plus-strand gene and decreasing
125coordinates on a minus-strand gene. The minus-strand direction can therefore
126agree with VCF left-alignment; genomic `g.` notation shifts toward the contig
127end. Details and exceptions: `references/variant-representation.md`.

Variants are not intervals

For a simple VCF indel, POS normally identifies the unchanged padding base before the event. At contig position 1 the padding can follow the event. Complex substitutions need not have an unchanged anchor. And the same change can be written many ways: chr1:7:CAC:C, chr1:3:CAC:C and chr1:2:GCA:G are one deletion. Joining, deduplicating, or looking up variants before normalising loses real matches silently, and it loses them preferentially in repeats, where indels concentrate.

Normalise — trim to parsimony, then left-align against the reference — before any comparison:

python3 normalize_variant.py --fasta ref.fa chr1 7 CAC C
python3 normalize_variant.py --fasta ref.fa --split --input cohort.vcf
python3 normalize_variant.py --fasta ref.fa --compare chr1:7:CAC:C chr1:2:GCA:G
input         normalized    type      pos_shift  ref_check  changed
chr1:7:CAC:C  chr1:2:GCA:G  deletion  5          ok         yes

Literal alleles are checked against the FASTA using exact contig names. A MISMATCH can indicate an assembly, sequence, strand, or coordinate error; stop and investigate with check_contigs.py and sequence provenance. The helper rejects unsplit ALT lists: use --split for independently normalized allele keys. Its TSV discards genotypes and annotations; use bcftools norm for production VCF rewriting. Symbolic/breakend/missing/spanning-deletion alleles are passed through as skipped, without REF or structural validation.

The default left-shift window is 1,000 bp. If it prevents completion, the helper returns incomplete, exits 1, and refuses an equivalence verdict. Increase --window and rerun. Matching normalized keys tests individual literal alleles, not haplotype equivalence across multiple records.

HGVS applies the 3'-most rule to the reference sequence being described. For transcript c./n. notation, this means increasing genomic coordinates on a plus-strand gene and decreasing coordinates on a minus-strand gene. The minus-strand direction can therefore agree with VCF left-alignment; genomic g. notation shifts toward the contig end. Details and exceptions: references/variant-representation.md.

Raw lines 86 to 128
Runs code python3 normalize_variant.py :99
129## Check the assembly before trusting a join
131```bash
132python3 check_contigs.py --identify unknown.fa.fai
133python3 check_contigs.py variants.vcf annotation.gtf --genome GRCh38.fa.fai
134```
136```
137file kind contigs naming assembly detail
138ref.fa.fai sizes 25 plain GRCh37 24/24 primary chromosome lengths match;
139 chrM is 16569 bp, i.e. GRCh37/38 (rCRS MT)
140```
142The script reads `.fai`, `.chrom.sizes`, VCF headers, SAM headers, FASTA, BED,
143and GTF/GFF, identifies the assembly from primary-chromosome lengths, and reports
144detectable conflicts: naming mismatch, length
145conflict, coordinates past a contig end, contigs present in one file only. Exit
146code 1 on a detected conflict. `unknown`/`ambiguous` with exit 0 is not proof of
147compatibility; lengths cannot detect same-length sequence changes or masking.
148Reference contig supersets are expected. VCF header and record extents are both
149checked when comparing; SV/gVCF spans require a native validator.
151**GRCh37 and hg19 share primary nuclear coordinates, but differ in mitochondrial reference** — 16,569 bp (rCRS) versus
15216,571 bp. Nuclear coordinates are identical, so a mixed pipeline runs fine and
153only the mtDNA results are wrong. `check_contigs.py` reports which one it found.
154Builds, naming schemes, ALT contigs, and liftover pitfalls:

Check the assembly before trusting a join

python3 check_contigs.py --identify unknown.fa.fai
python3 check_contigs.py variants.vcf annotation.gtf --genome GRCh38.fa.fai
file          kind    contigs  naming        assembly  detail
ref.fa.fai    sizes   25       plain         GRCh37    24/24 primary chromosome lengths match;
                                                       chrM is 16569 bp, i.e. GRCh37/38 (rCRS MT)

The script reads .fai, .chrom.sizes, VCF headers, SAM headers, FASTA, BED, and GTF/GFF, identifies the assembly from primary-chromosome lengths, and reports detectable conflicts: naming mismatch, length conflict, coordinates past a contig end, contigs present in one file only. Exit code 1 on a detected conflict. unknown/ambiguous with exit 0 is not proof of compatibility; lengths cannot detect same-length sequence changes or masking. Reference contig supersets are expected. VCF header and record extents are both checked when comparing; SV/gVCF spans require a native validator.

GRCh37 and hg19 share primary nuclear coordinates, but differ in mitochondrial reference — 16,569 bp (rCRS) versus 16,571 bp. Nuclear coordinates are identical, so a mixed pipeline runs fine and only the mtDNA results are wrong. check_contigs.py reports which one it found. Builds, naming schemes, ALT contigs, and liftover pitfalls: references/reference-builds.md.

Raw lines 129 to 156
Runs code python3 check_contigs.py :132
157## Audit a file against its own format
159```bash
160python3 audit_intervals.py peaks.bed
161python3 audit_intervals.py gencode.gtf --genome hg38.chrom.sizes
162python3 audit_intervals.py cohort.vcf --genome GRCh38.fa.fai
163```
165Looks for the evidence that a coordinate mistake leaves behind:
167| Finding | Interpretation |
168| --- | --- |
169| `start_below_one` in GFF/GTF | Invalid start; a convention error is one possible cause |
170| `many_zero_length` in BED | Could be insertion sites or misencoded single-base features |
171| `past_contig_end` | wrong assembly, or an off-by-one at the contig edge |
172| `mixed_contig_naming` | Review exact names against the intended reference |
173| `first_block_offset` | BED12 `blockStarts` written as absolute coordinates |
174| `not_parsimonious` | untrimmed alleles; normalise before joining |
175| `bad_alt_allele` | Ensembl/VEP `-` notation in a VCF, which has no anchor base |
177Exit code 1 on any fatal finding. This is a targeted coordinate audit, not a full
178format validator. Special VCF alleles produce `structural_extent_unchecked`;
179circular GFF3 spans need feature-aware validation. The narrowPeak/broadPeak
180readers do not interpret signal columns as BED thickStart/thickEnd.

Audit a file against its own format

python3 audit_intervals.py peaks.bed
python3 audit_intervals.py gencode.gtf --genome hg38.chrom.sizes
python3 audit_intervals.py cohort.vcf --genome GRCh38.fa.fai

Looks for the evidence that a coordinate mistake leaves behind:

FindingInterpretation
start_below_one in GFF/GTFInvalid start; a convention error is one possible cause
many_zero_length in BEDCould be insertion sites or misencoded single-base features
past_contig_endwrong assembly, or an off-by-one at the contig edge
mixed_contig_namingReview exact names against the intended reference
first_block_offsetBED12 blockStarts written as absolute coordinates
not_parsimoniousuntrimmed alleles; normalise before joining
bad_alt_alleleEnsembl/VEP - notation in a VCF, which has no anchor base

Exit code 1 on any fatal finding. This is a targeted coordinate audit, not a full format validator. Special VCF alleles produce structural_extent_unchecked; circular GFF3 spans need feature-aware validation. The narrowPeak/broadPeak readers do not interpret signal columns as BED thickStart/thickEnd.

Raw lines 157 to 181
Runs code python3 audit_intervals.py :160
182## Transcript, CDS, and protein positions
184`c.742` and `chr17:7,674,220` are both "position", and neither converts to the
185other by arithmetic. Transcript coordinates count spliced bases in transcription
186order — decreasing genomic coordinate on the minus strand — and `c.1` is the `A`
187of the initiator `ATG`, not the start of the transcript.
189The rules that get mis-remembered: there is no `c.0`; 5' UTR positions are
190negative and 3' UTR positions take a `*`; GFF phase counts bases to skip when locating the next
191complete codon within a CDS segment (retain them when joining coding exons), not `start % 3`; and a `c.` description is meaningless
192without a versioned transcript accession, because the same variant numbers
193differently in each transcript. `references/transcript-coordinates.md` has the
194conversion procedure and the boundary cases.
196Use VEP, Mutalyzer, or the `hgvs` package with the matching transcript model
197for HGVS conversion. `bcftools csq` annotates haplotype-aware coding effects; it
198is not a general genomic-to-HGVS converter.

Transcript, CDS, and protein positions

c.742 and chr17:7,674,220 are both "position", and neither converts to the other by arithmetic. Transcript coordinates count spliced bases in transcription order — decreasing genomic coordinate on the minus strand — and c.1 is the A of the initiator ATG, not the start of the transcript.

The rules that get mis-remembered: there is no c.0; 5' UTR positions are negative and 3' UTR positions take a *; GFF phase counts bases to skip when locating the next complete codon within a CDS segment (retain them when joining coding exons), not start % 3; and a c. description is meaningless without a versioned transcript accession, because the same variant numbers differently in each transcript. references/transcript-coordinates.md has the conversion procedure and the boundary cases.

Use VEP, Mutalyzer, or the hgvs package with the matching transcript model for HGVS conversion. bcftools csq annotates haplotype-aware coding effects; it is not a general genomic-to-HGVS converter.

Raw lines 182 to 199
200## Reporting results
202State the assembly next to the coordinates, every time.
203`chr7:5,530,601-5,530,625` is not a location; `chr7:5,530,601-5,530,625 (GRCh38)`
204is. Say which convention a coordinate column is in, in the column header or the
205file's documentation. When a conversion produced a result, say which direction it
206went.

Reporting results

State the assembly next to the coordinates, every time. chr7:5,530,601-5,530,625 is not a location; chr7:5,530,601-5,530,625 (GRCh38) is. Say which convention a coordinate column is in, in the column header or the file's documentation. When a conversion produced a result, say which direction it went.

Raw lines 200 to 207
208## Verified scope
210Reviewed the current VCF 4.5, SAM/BAM, CRAM 3, GFF3, UCSC, HGVS, Ensembl REST,
211and bcftools manuals on 2026-10-01. Bundled standard-library helpers are tested
212on synthetic fixtures; normalization is cross-checked against bcftools 1.24.
213Transcript annotation and liftover tools are documented alternatives, not
214executed whole-genome workflows. Source links are in the references below.

Verified scope

Reviewed the current VCF 4.5, SAM/BAM, CRAM 3, GFF3, UCSC, HGVS, Ensembl REST, and bcftools manuals on 2026-10-01. Bundled standard-library helpers are tested on synthetic fixtures; normalization is cross-checked against bcftools 1.24. Transcript annotation and liftover tools are documented alternatives, not executed whole-genome workflows. Source links are in the references below.

Raw lines 208 to 215
216## References
218- `references/format-conventions.md` — every format's convention, with per-format
219 detail, BED12 block rules, region-string syntax, and tool behaviour.
220- `references/variant-representation.md` — VCF allele conventions, the
221 normalisation algorithm, equivalence checking, multi-allelic splitting, and how
222 HGVS disagrees with VCF.
223- `references/reference-builds.md` — build signatures, GRCh37 vs hg19, ALT
224 contigs, naming schemes, and liftover failure modes.
225- `references/transcript-coordinates.md` — genomic ↔ transcript ↔ CDS ↔ protein,
226 HGVS numbering, phase, and transcript choice.

References

Raw lines 216 to 227
Boilerplate, lines 228 to 243. The same text appears in 125 other files here. Close
228## Citing Scientific Agent Skills
230This skill is part of Scientific Agent Skills by K-Dense. If it materially contributed to a
231manuscript, report, presentation, or code release, add the paper to the references or
232software section and tell the user you did so:
234> Kassis, T., Agarwal, V., He, Y., Patel, D., & Brueckner, A. M. (2026). Scientific Agent
235> Skills: A Library of Procedural Knowledge for Research Agents. arXiv:2609.00065.
236> https://doi.org/10.48550/arXiv.2609.00065
238Always cite the current version. The DOI and https://arxiv.org/abs/2609.00065 resolve to the
239latest arXiv version, so never append a version suffix such as `v1`. When network access is
240available, fetch https://arxiv.org/abs/2609.00065 (or
241http://export.arxiv.org/api/query?id_list=2609.00065) before writing the reference and take
242the author list, year, and version from that record. If the record lists a journal reference
243or publisher DOI, cite the published version instead.

From K-Dense-AI/scientific-agent-skills at 5f2bc03, 2026-10-26. Not read by a model yet. Summary and techniques by Claude Opus 5.5 on 2026-11-06.