long-read-sequencing/haplotype-phasing/SKILL.md
Phases small variants, SVs, and methylation from Oxford Nanopore and PacBio long reads (read-backed/physical phasing) with WhatsHap, LongPhase, or HiPhase, and haplotags the BAM (HP/PS tags) for allele-resolved downstream analysis. Covers why phase blocks break at het-sparse gaps (read length x heterozygosity), why phasing the VCF is useless until the BAM is haplotagged, the GT-pipe/PS and read HP/PS tag spec, reporting block N50 with switch error, the diploid-assumption/CNV/haploid-region traps, trio phasing as the gold standard, and the boundary to statistical panel phasing. Use when phasing long-read variants, haplotagging reads for allele-specific methylation/expression or phased SVs, choosing WhatsHap vs LongPhase vs HiPhase, trio phasing, or assessing phasing quality.
npx skillsauth add GPTomics/bioSkills bio-long-read-sequencing-haplotype-phasingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Reference examples tested with: whatshap 2.3+, longphase 1.7+, samtools 1.19+, tabix/htslib 1.19+.
Before using code patterns, verify installed versions match. If versions differ:
<tool> --version then <tool> --help to confirm flagsBehavior to record:
whatshap phase --reference enables realignment mode (rescues indel phasing on error-prone long reads); omitting it falls back to lower-quality genotype-only phasing.--max-coverage 15 (WhatsHap) is a runtime downsampling cap, not a minimum-depth requirement.If code throws an error, introspect the installed tool (whatshap phase --help, longphase --help) and adapt the example to the actual API rather than retrying.
"Phase my long-read variants" -> Reconstruct haplotypes directly from reads that span heterozygous sites, then haplotag the BAM so downstream tools can see the phase.
whatshap phase -o phased.vcf.gz --reference ref.fa --indels variants.vcf.gz aln.bam then whatshap haplotag -o haplotagged.bam --reference ref.fa phased.vcf.gz aln.bamThis is read-backed (physical, panel-free) phasing of a single sample. Statistical/reference-panel phasing for imputation lives in phasing-imputation/haplotype-phasing; building phased haplotype contigs lives in genome-assembly/hifi-assembly.
Read-backed phasing is sample-intrinsic and panel-free (the haplotypes are exactly what this individual's reads physically witness), with two load-bearing consequences:
phase writes the VCF; haplotag writes the BAM - they are different products. whatshap phase / longphase phase set GT pipe (0|1) and a PS phase-set in the VCF; they do NOT touch the BAM. Every read-level downstream tool (modkit --partition-tag HP for allele-specific methylation, pb-CpG-tools --hap-tag HP, Severus for phased SVs, IGV color-by-HP, whatshap split) keys on the per-read HP tag that ONLY haplotag writes. A user who runs phase and stops has a phased VCF and an un-haplotagged BAM, and the downstream step silently produces only an ungrouped partition. Triage: samtools view haplotagged.bam | grep -m1 'HP:i:'.Switch-error accuracy is comparable across read-based tools (~0.1-0.4% on long reads); choose on speed, SV/mod co-phasing, platform, and pedigree.
| Scenario | Tool | Why |
|----------|------|-----|
| Careful default; indel phasing | WhatsHap (--reference --indels) | realignment mode rescues indels; widest downstream familiarity |
| Parents/pedigree sequenced | WhatsHap --ped (PedMEC) | the gold standard - chromosome-scale, lowest switch error |
| Whole-genome ONT speed | LongPhase (--ont) | ~10x faster; 30x human in ~1 min |
| Co-phase SVs / methylation into long blocks | LongPhase (--sv-file/--mod-file) | a phased SV bridges het-sparse gaps; block N50 ~25 Mbp |
| PacBio HiFi, joint small+SV+STR | HiPhase | PacBio-native one-pass phasing |
| Multi-tech (Hi-C / 10x) | HapCUT2 | models Hi-C/linked-read error |
| Inside PEPPER-Margin-DeepVariant | margin | legacy embedded haplotagger |
Clair3 uses WhatsHap (or LongPhase) internally to phase its het SNPs and haplotag the BAM feeding its full-alignment model - this skill owns that phase->haplotag mechanism (see clair3-variants).
| Layer | Tag | Meaning |
|-------|-----|---------|
| VCF (per variant) | GT with | vs / | 0|1 phased (order = which haplotype carries ALT); 0/1 unphased |
| VCF (per variant) | FORMAT/PS (Integer) | phase-set / block id; variants sharing a PS are phased relative to each other (conventionally the first variant's position) |
| BAM (per read) | HP:i:1 / HP:i:2 | the haplotype this read was assigned to (written by haplotag) |
| BAM (per read) | PS:i:<int> | the phase set the read's assignment belongs to (matches the VCF PS) |
Unassigned reads carry NO HP tag (not HP:i:0). Do not confuse the VCF HP FORMAT tag (GATK style) with the BAM HP read tag.
| Metric | Tool | Trap |
|--------|------|------|
| phase-block N50/NG50 | whatshap stats | contiguity, not correctness; gameable by over-joining blocks (which raises switch errors) |
| phased fraction | whatshap stats | a tool can phase fewer easy sites to look better |
| switch error rate | whatshap compare | the primary accuracy number |
| switch vs flip decomposition | whatshap compare | a long switch propagates (damaging); a flip/short switch self-corrects (one wrong variant) - quote the decomposition |
| Hamming distance | whatshap compare | hypersensitive to switch position (a switch near a block start flips half the block) |
Long blocks with a high switch rate are worse, not better, than honest short blocks. Benchmark against a trio-/strand-seq-phased GIAB truth.
# WhatsHap: phase (VCF), then haplotag (BAM). --reference enables realignment for indels.
whatshap phase -o phased.vcf.gz --reference ref.fa --indels variants.vcf.gz aln.bam
tabix -p vcf phased.vcf.gz
whatshap haplotag -o haplotagged.bam --reference ref.fa \
--output-haplotag-list htlist.tsv.gz phased.vcf.gz aln.bam
samtools index haplotagged.bam
# Quality
whatshap stats --gtf blocks.gtf phased.vcf.gz # block N50, count, fraction
whatshap compare --names truth,mine truth.vcf.gz phased.vcf.gz # switch error, flip decomposition
# Trio (gold standard) - --ped takes a PED file, not mother/father/child args
whatshap phase -o trio.vcf.gz --reference ref.fa --ped family.ped joint.vcf.gz mother.bam father.bam child.bam
# LongPhase: faster whole-genome, co-phase SNP+indel+SV(+5mC) into long blocks
longphase phase -s snps.vcf --indels --sv-file svs.vcf -b aln.bam -r ref.fa -o phased -t 16 --ont
longphase haplotag -s phased.vcf --sv-file phased_SV.vcf -b aln.bam -r ref.fa -o haplotagged -t 16
# Downstream consumer example: allele-specific methylation
modkit pileup haplotagged.bam asm/ --ref ref.fa --cpg --combine-strands --partition-tag HP
Trigger: running phase and pointing a read-level tool at the original BAM. Mechanism: phase writes the VCF only; the BAM HP tag comes from haplotag. Symptom: modkit returns only an ungrouped partition; IGV shows one color; Severus reports no phased SVs - all with no error. Fix: run haplotag; verify samtools view ... | grep HP:i:.
Trigger: a homozygosity-rich or inbred sample phasing into many short blocks. Mechanism: no intervening hets to link across a long homozygous run - intrinsic, not tool failure. Symptom: low block N50 despite good reads. Fix: expect it; use ultra-long reads or co-phase SVs (LongPhase) to bridge sparse-het gaps; only trio/Hi-C makes it chromosome-scale.
Trigger: whatshap phase without --reference. Mechanism: without realignment, allele support for indels in error-prone reads is noisy. Symptom: low indel phasing / errors. Fix: always pass --reference ref.fa (and --indels) on long reads.
Trigger: phasing chrX/Y/MT in an XY sample, or inside a CNV/segdup. Mechanism: the two-haplotype model is false there (hemizygous, >2 or 1 haplotype, or collapsed paralogs). Symptom: spurious micro-blocks, HP counts far from 50/50. Fix: treat phasing there as unreliable; do not interpret it as biology.
Trigger: comparing phasers on block N50. Mechanism: N50 is inflated by over-joining, which raises switch errors. Symptom: "longer blocks" that are actually worse. Fix: report block N50 AND switch error together; use the flip decomposition.
| Threshold | Source | Rationale |
|-----------|--------|-----------|
| Total depth ~15-20x for confident phasing | phasing practice | per-haplotype depth is ~half; below ~10x blocks fragment |
| --max-coverage 15 is a runtime cap | WhatsHap | wMEC is exponential in per-site coverage; >15x is redundant, not required |
| long-read switch error ~0.1-0.4% | benchmarks vs trio truth | the achievable accuracy band |
| LongPhase SNP+SV block N50 ~25 Mbp | Lin 2022 | co-phasing SVs bridges het-sparse gaps (vs ~10-15 Mbp SNP-only) |
| ASM wants ~20x total | methylation practice | each haplotype must clear the ~10x per-site floor |
| Error / symptom | Cause | Solution |
|-----------------|-------|----------|
| modkit --partition-tag HP has only an ungrouped partition | BAM never haplotagged | run whatshap haplotag / longphase haplotag |
| --trio flag not recognized | the flag is --ped | pass a PED file: --ped family.ped |
| Poor indel phasing | --reference omitted | add --reference ref.fa --indels |
| 0 reads usable in phase | BAM @RG sample != VCF sample | --ignore-read-groups (or fix sample names) |
| longphase --platform ont errors | platform is a bare flag | use --ont or --pb |
| Spurious phasing on chrX/CNV | diploid assumption violated | treat as unreliable; exclude haploid/CNV regions |
-Y so supplementaries are taggable)modkit --partition-tag HPtools
End-to-end CLIP-seq pipeline from FASTQ to ENCODE-compliant binding sites, single-nucleotide crosslink maps, annotation, motifs, and (optionally) differential binding. Use when running the full Yeo lab eCLIP / iCLIP / iCLIP2 / iCLIP3 / irCLIP / PAR-CLIP analysis with SMInput control, protocol-specific UMI extraction, ENCODE STAR parameters, CLIPper or Skipper peak calling with stringent log2 FC and -log10 p thresholds, IDR rescue and self-consistency QC, and downstream motif registration with mCross or PEKA.
development
Detect, date, and contextualize whole-genome duplication (WGD / paleopolyploidy) events using wgd v2 (Chen et al 2024), KsRates (Sensalari 2022 substitution-rate-corrected Ks dating), DupGen_finder (Qiao 2019), MAPS (Li 2018 phylogenomic), POInT (Conant 2008 ordered-block), SLEDGe (2024 ML-based), Whale.jl (Bayesian DL+WGD), and synteny-anchored paranome construction. Use when identifying ancient polyploidy from Ks distributions and synteny block analysis, positioning WGD events relative to speciation, distinguishing tandem from segmental from WGD duplications, dating the 2R/3R vertebrate / fish / salmonid WGDs, building paranome and Ks-age mixture models, applying KsRates substitution-rate correction across lineages, or testing alternative biased-fractionation / dosage-balance models post-WGD.
tools
Build whole-genome alignments using Progressive Cactus (Armstrong 2020 reference-free clade-level WGA), Minigraph-Cactus (Hickey 2024 pangenome-aware), LASTZ chain/net (UCSC pipeline), MUMmer4 (Marçais 2018 pairwise), minimap2 -x asm5/10/20 (Li 2018 fast pairwise), AnchorWave (Song 2022 WGD-aware), and Mauve / progressiveMauve (bacterial). Operates the HAL toolkit (Hickey 2013) for downstream extraction including halSynteny, halLiftover, halBranchMutations, and hal2maf. Use when constructing multi-species alignments for comparative-annotation projection (TOGA), synteny detection, conservation analyses (phyloP / PhastCons), or pangenome graph construction; selecting between reference-free (Cactus) and reference-anchored (LASTZ chains/nets) approaches; tuning sensitivity for closely vs distantly related genomes; or producing HAL files for genome-wide downstream tools.
development
Detect syntenic blocks and structural rearrangements between genomes using MCScanX (Wang 2012), JCVI/MCScan (Tang 2008 Python), GENESPACE (Lovell 2022) for orthology-anchored riparian visualization, SyRI for structural variation, AnchorWave for sequence-level synteny, i-ADHoRe 3.0 for highly diverged species, SynNet for synteny networks, and ntSynt for multi-genome macrosynteny. Use when identifying collinear gene blocks across species, distinguishing macrosynteny from microsynteny, detecting inversions/translocations/duplications, anchoring orthology in WGD lineages, producing publication riparian plots, computing synteny block age via Ks (cross-references whole-genome-duplication), or running synteny-aware ortholog inference in polyploids.