pku-yuangroup/openai4s/bio-alignment-files-alignment-validation
Claude Code and agent skill by pku-yuangroup/openai4s
- community
Checking that the SKILL.md file is still in the repository.
Validate alignment quality with insert size distribution, proper pairing rates, GC bias, strand balance, and other post-alignment metrics. Use when verifying alignment data quality before variant calling or quantification.
Install
npx vskill@latest install pku-yuangroup/openai4s/bio-alignment-files-alignment-validationSKILL.md
The same SKILL.md was published earlier as pku-yuangroup/openai4s/bio-alignment-files-alignment-validation.
Version Compatibility
Reference examples tested with: matplotlib 3.8+, numpy 1.26+, picard 3.1+, pysam 0.22+, samtools 1.19+
Before using code patterns, verify installed versions match. If versions differ:
- Python:
pip show <package>thenhelp(module.function)to check signatures - CLI:
<tool> --versionthen<tool> --helpto confirm flags
If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
Alignment Validation
Post-alignment quality control to verify alignment quality and identify issues.
"Check alignment quality" -> Compute post-alignment QC metrics (mapping rate, pairing, insert size, strand balance) to identify issues before downstream analysis.
- CLI:
samtools flagstat,samtools stats, PicardCollectAlignmentSummaryMetrics - Python:
pysam.AlignmentFileiteration with metric calculations
Two Different Validations
| Concern | Tools | What it catches | |
|---|---|---|---|
| File integrity | samtools quickcheck, picard ValidateSamFile | Truncation, missing EOF, malformed records, wrong CIGAR, MAPQ out of range | |
| Sequence dictionary identity | samtools dict + M5 diff | BAM aligned to wrong reference flavor / different decoy / chr vs no-chr | |
| QC metrics | samtools stats, flagstat, mosdepth, Picard CollectMultipleMetrics / CollectHsMetrics / CollectWgsMetrics | Are the data biologically reasonable for the assay? | |
| Contamination / sample swap | verifybamid2, somalier, Picard CrosscheckFingerprints | Cross-sample contamination, tumor-normal swap, mislabeled sample |
A file can pass quickcheck and still be malformed in ways that crash GATK three hours into HaplotypeCaller. Conversely, a QC-poor BAM can be structurally valid.
File Integrity
CI-safe one-liner:
Sequence Dictionary Cross-Validation (M5)
If M5s differ, the BAM was aligned to a different sequence than the current reference (even if contig names match). Concrete failure modes: GRCh38 vs GRCh38.p13 vs GRCh38_no_alt (alt contigs differ); UCSC chr1 vs Ensembl 1 (names differ, M5s match -- pure renaming); soft-masked vs unmasked (M5 matches -- case is normalized to uppercase before hashing, so lowercase soft-masking is invisible to M5). Note hard-masking is different: it replaces bases with N, changing the sequence, so its M5 does NOT match the unmasked reference. The M5 tag is the only definitive identity check.
Contamination and Sample Swap
No alignment QC is complete without these in production:
Sample-swap rates of 0.5-1% in production cohorts are typical. Without somalier or CrosscheckFingerprints, swaps are detected only when a downstream finding contradicts clinical expectation.
Insert Size Distribution
Goal: Verify that the fragment length distribution matches the library preparation protocol.
Approach: Extract template_length from properly paired reads and compare the distribution to expected values for the library type.
samtools stats
Picard CollectInsertSizeMetrics
Expected Insert Sizes by Library
| Library | Mean insert | Distribution shape | Diagnostic | |
|---|---|---|---|---|
| TruSeq DNA PCR-free WGS | 400-500 bp | Roughly Gaussian, tight/sharp | Sharpest, most symmetric peak (no PCR bias); bimodality = degraded sample | |
| TruSeq DNA Nano (PCR) WGS | 300-400 bp | Gaussian, broadened by PCR amplification bias | ||
| Twist / IDT exome capture | 250-350 bp | Gaussian | ||
| TruSeq Stranded mRNA | 200-300 bp | Right-skewed (transcript distribution) | Long tail = poor size selection | |
| Ribo-Zero rRNA-depleted | 250-400 bp | Right-skewed | ||
| Smart-seq2 / Smart-seq3 | 200-700 bp | Broad | ||
| 10x Chromium (3') | n/a -- not informative | n/a | ||
| TruSeq ChIP | 200-400 bp | Sharp | ||
| ATAC-seq (Buenrostro / Omni-ATAC) | Multimodal | Peaks at ~50, ~180, ~370 bp | Missing multimodal pattern = bad library; missing ~180 bp mononucleosome peak = over-transposition (Tn5 over-titrated) or degraded DNA | |
| Hi-C / Micro-C | Multimodal | Peak at ligation-junction size | ||
| cfDNA / ctDNA | 160-180 bp | Multimodal; ~167 bp mononucleosomal + ~340 dinuc | Tumor-derived shorter (~145 bp); shape itself is a biomarker | |
| FFPE | 100-250 bp | Right-skewed, broad | ||
| aDNA | 30-80 bp | Sharp left-skewed | ||
| ONT (native) | 1-30 kb | n/a | ||
| PacBio HiFi | 10-25 kb | Sharp peak |
For ATAC, the multimodal pattern is the QC. If the mononucleosomal peak (~180 bp) is absent, Tn5 was over-titrated, under-titrated, or DNA was degraded. Use ATACseqQC fragSizeDist() for the standard ATAC fragment-size diagnostic.
Python Insert Size Analysis
Proper Pairing Rate
Percentage of reads correctly paired.
samtools flagstat
Calculate Pairing Rate
Expected Rates
| Metric | Good | Marginal | Poor | |
|---|---|---|---|---|
| Proper pair | > 90% | 80-90% | < 80% | |
| Mapped | > 95% | 90-95% | < 90% | |
| Singletons | < 5% | 5-10% | > 10% |
GC Bias
GC content correlation with coverage.
Picard CollectGcBiasMetrics
deepTools computeGCBias
Interpret GC Bias
| Issue | Symptom | |
|---|---|---|
| Under-representation | Low GC coverage drops | |
| Over-representation | High GC coverage elevated | |
| PCR bias | Strong correlation |
Strand Balance
A balanced 0.48-0.52 forward/reverse ratio applies to WGS / WES / generic DNA-seq on autosomes. Expected to deviate for: stranded RNA-seq (deliberately strand-asymmetric -- verify with RSeQC infer_experiment.py), bisulfite (CT vs GA), small-RNA / strand-specific RNA-seq, and chrY/chrM regions. Per-chromosome strand imbalance >5% on autosomes is a field-convention rule of thumb (no single primary citation) — it picks up aligner artifacts; on chrX/chrY it suggests sex-mismatch.
Calculate Strand Ratio
Check Strand Bias per Chromosome
Mapping Quality Distribution
Extract MAPQ Distribution
Calculate Mean MAPQ
MAPQ Distribution Is Bimodal and Aligner-Specific
Mean MAPQ is misleading; distributions are bimodal (0 and aligner-max). For aligner-specific scales and "unique mapping" sentinels, see sam-bam-basics. The fraction of primary mapped reads at MAPQ >= 30 is a more informative summary than the mean.
Chromosome Coverage Balance
Calculate Per-Chromosome Coverage
Check for Aneuploidy / Sex Chromosome Imbalance
Median-normalized per-autosome coverage (1.0 = expected diploid; 0.5 = monosomy/sex; 1.5 = trisomy):
For full ancestry / contamination / relatedness checking, use verifybamid2, somalier, or peddy -- they account for population AFs, not just per-contig depth.
Mismatch Rate
Picard CollectAlignmentSummaryMetrics
Key Metrics
| Metric | Description | Good Value | |
|---|---|---|---|
| PCT_PF_READS_ALIGNED | Mapped % | > 95% | |
| PF_MISMATCH_RATE | Mismatches | < 1% | |
| PF_INDEL_RATE | Indels | < 0.1% | |
| STRAND_BALANCE | Strand ratio | ~0.5 |
Comprehensive Validation Script
Goal: Run all key alignment QC checks in a single pass and generate a summary report.
Approach: Combine samtools flagstat, stats, idxstats, and strand counts into one script that outputs pass/warn/fail calls.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/bioskills/bio-alignment-files-alignment-validation/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Grok Build (Cursor)
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/pku-yuangroup/openai4s/bio-alignment-files-alignment-validation)