pku-yuangroup/openai4s/bio-alignment-files-reference-operations
Claude Code and agent skill by pku-yuangroup/openai4s
- community
Checking that the SKILL.md file is still in the repository.
Generate consensus sequences and manage reference files using samtools. Use when creating consensus from alignments, indexing references, or creating sequence dictionaries.
Install
npx vskill@latest install pku-yuangroup/openai4s/bio-alignment-files-reference-operationsSKILL.md
The same SKILL.md was published earlier as pku-yuangroup/openai4s/bio-alignment-files-reference-operations.
Version Compatibility
Reference examples tested with: GATK 4.5+, bcftools 1.19+, 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.
Reference Operations
Generate consensus sequences and manage reference files using samtools.
"Prepare a reference genome" -> Index the FASTA and create a sequence dictionary for downstream tools.
- CLI:
samtools faidx ref.fa+samtools dict ref.fa -o ref.dict - Python:
pysam.FastaFile('ref.fa')(auto-uses .fai index)
"Build a consensus from BAM" -> Derive the most-supported base at each position from aligned reads.
- CLI:
samtools consensus input.bam -o consensus.fa - Python: iterate pileup columns and take majority base (pysam)
samtools faidx - Index Reference FASTA
Create index for random access to reference sequences.
Create Index
Fetch Region from Reference
Fetch Multiple Regions
Fetch Entire Chromosome
Output to File
Reverse Complement
FAI File Format
Columns: name, length, offset, line bases, line width
samtools dict - Create Sequence Dictionary
Create SAM header dictionary for reference (used by GATK, Picard).
Create Dictionary
With Assembly Info
Dictionary Format
The M5: (MD5) tag is the only definitive reference-identity check -- two references named "GRCh38" with different decoy/alt content have different M5s. CRAM enforces M5 match on read-back. See alignment-validation for BAM-vs-reference M5 cross-check.
GRCh38 Is Not One Reference
| Reference flavor | ALT | Decoy | EBV | HLA | Use case | |
|---|---|---|---|---|---|---|
| GRCh38 no-alt | no | no | no | no | Conservative analyses | |
| GRCh38 + decoy + EBV (1000G analysis set) | no | yes | yes | no | Cohort projects | |
| GRCh38 ALT + decoy + EBV + HLA (Broad / hs38DH) | yes | yes | yes | yes | GATK Best Practices | |
| T2T-CHM13 v2.0 | n/a | n/a | n/a | n/a | Distinct coordinates -- NOT interchangeable |
Mixing no-alt and ALT-aware BAMs in one cohort produces inconsistent multi-mapping behavior at HLA, KIR, and segmental-duplication regions. Standardize before joint calling.
Contig Naming: The Silent Killer
| Convention | Source | chr1 | mitochondrion | |
|---|---|---|---|---|
| UCSC (hg19, hg38) | UCSC Genome Browser | chr1 | chrM | |
| Ensembl (GRCh37, GRCh38) | Ensembl, ENA | 1 | MT | |
| NCBI RefSeq (recent) | NCBI | chr1 | chrM | |
| 1000G analysis sets | 1000G GRCh38 analysis set | chr1 | chrM |
A BAM with @SQ SN:chr1 cannot be analyzed against a 1-named reference (and vice versa). Detect:
Convert: bcftools annotate --rename-chrs for VCF; for BAM there is no clean conversion -- re-align.
samtools consensus - Generate Consensus
Create consensus sequence from alignments.
Basic Consensus
From Specific Region
Output Formats
Quality Options
IUPAC Ambiguity for Heterozygotes
--het-fract controls the fraction of the second-most-common base relative to the most common required to call a heterozygote (verify the default for the installed version with samtools consensus --help; the manpage documents none). Without --ambig, columns where the second base passes --het-fract resolve to N rather than the IUPAC code. --show-ins / --show-del control insertion / deletion display, not ambiguity.
Platform-Aware Consensus
samtools consensus vs bcftools consensus
Different operations -- conflating them produces nonsense:
| Tool | Input | Output | Use case | |
|---|---|---|---|---|
samtools consensus | BAM | Consensus FASTA derived from reads (Bayesian) | Viral, de novo / amplicon, low-coverage species | |
bcftools consensus | reference + VCF | Reference with VCF variants applied | Apply called variants (haplotype reconstruction, custom ref for re-mapping) |
For viral consensus from BAM:
For bacterial / phage assembly polishing, prefer Pilon (short-read) or medaka (ONT); samtools consensus is not iterative.
pysam Python Alternative
Fetch from Indexed FASTA
Get Reference Lengths
Fetch All Chromosomes
Generate Simple Consensus
Build Consensus Sequence (Pedagogical Only)
The Python majority-vote consensus below is illustrative, NOT production. samtools consensus is Bayesian, quality-aware, and platform-aware; majority vote ignores base qualities and produces wrong calls on low-coverage / low-quality regions. Use for teaching pileup iteration mechanics; use samtools consensus for any real consensus.
Create Dictionary Header
Reference Preparation Workflow
Goal: Set up a reference genome with all indices needed by common analysis tools.
Approach: Create FASTA index (.fai), sequence dictionary (.dict), and aligner-specific indices in sequence.
Prepare Reference for Analysis
For aligner-specific indices (BWA, Bowtie2, STAR, minimap2, Salmon), see read-alignment.
Check Reference Setup
Common Operations
Extract Chromosome
Get Chromosome Sizes
Subset Reference
Compare Consensus to Reference
Quick Reference
| Task | Command | |
|---|---|---|
| Index FASTA | samtools faidx ref.fa | |
| Fetch region | samtools faidx ref.fa chr1:1-1000 | |
| Create dict | samtools dict ref.fa -o ref.dict | |
| Build consensus | samtools consensus in.bam -o out.fa | |
| Chrom sizes | cut -f1,2 ref.fa.fai |
Related Skills
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-reference-operations/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-reference-operations)