Imported from paulstothard/genotype_converter (
AGENTS.md). Install upstream withnpx skills add paulstothard/genotype_converter. Copyright stays with the author.
Repository Notes for Agents
Validation Safety
- Do not run the full bovine HD validation panel unless the user explicitly asks.
The local reference FASTA is large, and
--aligncreates a very large alignment display file. - Prefer
--workers 1for full validation unless the user confirms the machine has memory for one minimap2 reference index per worker. - Use the validation helper scripts instead of reconstructing long commands by
hand. The main scripts are:
validation/scripts/run_bovine_hd_build.shvalidation/scripts/run_bovine_hd_compare.shvalidation/mixed_manifest/scripts/run_make_example_genotypes.shvalidation/mixed_manifest/scripts/run_discover_sources.shvalidation/mixed_manifest/scripts/run_database_build.shvalidation/mixed_manifest/scripts/run_example_conversions.shvalidation/mixed_manifest/scripts/run_check_example_conversions.shvalidation/plink_comparison/scripts/run_plink_comparison.shvalidation/plink_comparison/scripts/compare_plink_bim.py
- Do not run
validation/scripts/run_bovine_hd_build.shorvalidation/mixed_manifest/scripts/run_database_build.shunless the user explicitly asks for the large build. The mixed-manifest database build script also requires--yesto make accidental starts harder. - Do not stage or commit large validation inputs or generated outputs under
validation/data/,validation/old_pipeline/, orvalidation/new_pipeline/. These are intentionally ignored. - Do not stage or commit collaborator PLINK files or generated reports under
validation/plink_comparison/input/,validation/plink_comparison/converted/, orvalidation/plink_comparison/reports/. - Do not change old pipeline outputs. If a comparison needs normalization, create a separate report or helper output and document the command.
- Do not change test expectations just to make a failing test pass. If expected output changes, explain the biological or file-format reason.
Genotype Conversion Policy
- A lookup CSV is the
*.lookup.csvoutput from onebuildrun for one manifest/reference pair.--lookuppoints directly to that single file. - SQLite database mode is for many manifests, many assemblies, or mixed-manifest genotype inputs. Keep lookup CSV workflows supported; the database must remain optional.
buildwrites a site-only*.sites.vcfby default.export-vcfcan also write one from a lookup CSV or one SQLite database source. This VCF has nucleotideREF/ALTalleles and noFORMATor sample genotype columns. Do not add0/1genotype indexes unless a future workflow explicitly has sample genotypes to encode.- Database source folders use
database_sources/<species>/manifests/anddatabase_sources/<species>/references/<assembly>/. Manifests are independent of reference genomes; the database builder pairs every manifest with every reference assembly for that species. reference download-ncbiis the user-facing reference download helper. It writes intodatabase_sources/<species>/references/<assembly>/, preserves the assembly report, and keeps assembled molecules plus unlocalized/unplaced scaffolds by default.- The same marker name can appear in multiple manifests. Do not collapse rules across manifest/source contexts, and keep mixed-manifest resolution conservative and reportable.
convert,convert-plink, andconvert-pfileall use--on-unconvertible-marker exclude|fail|keep.- The default is
excludefor text formats and PLINK formats. - For text
convertlayouts,excluderemoves unconvertible marker columns from wide CSV and marker rows from long, Illumina, and Affymetrix-style outputs. It writes<output>.marker_conversion_report.csvand, when markers are excluded,<output>.exclude_markers.txt. - For
convert-plink,excludemust use PLINK to remove variants before rewriting.bim, so.bed/.bim/.famremain synchronized. Do not manually filter.bimwithout rewriting.bed. - For
convert-pfile,excludemust use PLINK2 to remove variants before rewriting.pvar, so.pgen/.pvar/.psamremain synchronized. - Missing marker IDs and incomplete allele mappings are tracked separately.
Text summaries use
markers_missing_lookup,markers_incomplete_mapping,markers_excluded, andgenotypes_excluded. PLINK summaries usevariants_missing_lookup,variants_incomplete_mapping, andvariants_excluded. keepis for audit/debugging runs where unresolved allele values should be left unchanged.failis for strict checking after writing the marker report.- The conda environment installs PLINK 1, not PLINK 2.
convert-pfileshould fail clearly when PLINK2 is needed for filtering and cannot be found.
Documentation Hygiene
- Keep
README.md,docs/database.md,docs/genotype-formats.md, anddocs/development-plan.mdaligned when behavior changes. - The README should keep two distinct end-to-end examples: one for the single lookup CSV workflow and one for the SQLite database workflow.
- User-facing docs should explain workflows in terms of user decisions and inputs. Do not include internal slogans, conversation artifacts, or collaborator-specific names/details in tracked docs or helper scripts.
- Do not add performance/runtime tables unless they come from a reproducible benchmark or recorded validation run. Use qualitative memory and worker guidance instead.
docs/development-plan.mdrecords repo-level status and future work. Remove or update items when they are implemented so it does not become a stale TODO list.
Probe-Adjacent SNP Positioning
For Illumina SNP manifests, AlleleA_ProbeSeq and AlleleB_ProbeSeq describe
the assay probe context. A probe may stop next to the assayed base, or it may
include the assayed allele as its terminal base. When probe placement is
detectable:
- A left-side probe reports the first reference base immediately after the probe in the alignment when the probe is adjacent-only.
- A right-side probe reports the first reference base immediately before the probe in the alignment when the probe is adjacent-only.
- An allele-including probe reports the matching allele base in the probe itself.
- If
AlleleA_ProbeSeqandAlleleB_ProbeSeqimply incompatible sides or incompatible assayed positions, classify the site as ambiguous unless oriented manifest alleles uniquely resolve the candidate position. - Reverse-complement probe matches are valid because the selected reference hit may be on the minus strand.
- When the selected hit is on the minus strand, orient the probe placement as a unit: flip the side and reverse-complement the probe sequence. Do not flip only the side label; that causes the probe lookup to fail and silently falls back to direct CIGAR mapping near gaps.
- This probe-adjacent rule is especially important when the synthetic
NinSourceSeqis next to a CIGAR insertion/deletion. In those cases, directN-to-reference CIGAR mapping can choose the wrong neighboring base for the assay. - The synthetic
Nreplacing the bracketed allele site must be tracked by position. Do not strip real flankingNbases from the minimap2 query; they are part of the manifest sequence context and should not be confused with the assayed-site placeholder. - If the probe can be placed uniquely on the selected reference neighborhood,
that reference-side probe placement defines the assayed base. Direct CIGAR
mapping of the synthetic
Nis a fallback/check and must not overrule a clear reference-side probe placement. - If only query-side probe placement is available and the probe-derived coordinate differs from the direct CIGAR coordinate, manifest alleles may be used as a tie-breaker only when exactly one candidate reference base is compatible with the oriented SNP alleles. If zero or multiple candidates are compatible, keep the probe-derived coordinate and classify the site as ambiguous.
- For SNPs with a CIGAR gap near the tracked assayed site, local realignment of a short reference window is allowed before probe/allele resolution. Keep this refinement SNP-only; indel placement and VCF anchoring have separate logic.
- If probe side cannot be determined, fall back to direct CIGAR mapping of the
synthetic
N. - Build outputs include
determination_typein position, wide, lookup, and optional Parquet outputs. Preserve this QC column when changing output schemas. - Track exact old/new validation discrepancy counts in generated validation reports, not in this file. Historically, remaining nearby discrepancies have often been gap-adjacent, so inspect the selected CIGAR and probe placement before changing positioning logic.
User-facing docs should describe this as probe-based or probe-adjacent SNP positioning. Avoid internal slogans or implementation jargon in user-facing docs.