pku-yuangroup/openai4s/bio-alignment-alignment-io
Claude Code and agent skill by pku-yuangroup/openai4s
- community
Checking that the SKILL.md file is still in the repository.
Read, write, and convert multiple sequence alignment files using Biopython Bio.AlignIO. Supports Clustal, PHYLIP, Stockholm, FASTA, Nexus, and other alignment formats for phylogenetics and conservation analysis. Use when reading, writing, or converting alignment file formats.
Install
npx vskill@latest install pku-yuangroup/openai4s/bio-alignment-alignment-ioSKILL.md
The same SKILL.md was published earlier as pku-yuangroup/openai4s/bio-alignment-alignment-io.
Version Compatibility
Reference examples tested with: BioPython 1.83+
Before using code patterns, verify installed versions match. If versions differ:
- Python:
pip show <package>thenhelp(module.function)to check signatures
If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
Alignment File I/O
Read, write, and convert multiple sequence alignment files in various formats.
Required Import
Goal: Load modules for reading, writing, and manipulating multiple sequence alignments.
Approach: Import AlignIO for file I/O and supporting classes for programmatic alignment construction.
Format Coverage Map
Three Python libraries cover the alignment-format space, with overlapping but non-identical support. Pick by what is actually required.
| Format | Bio.AlignIO | Bio.Align (modern) | pyhmmer.easel | Notes | |
|---|---|---|---|---|---|
| Aligned FASTA | R/W | R/W | R/W | Most portable; loses annotations | |
| Clustal | R/W | R/W | R | Clustal conservation marks NOT round-tripped | |
| PHYLIP (interleaved/sequential/relaxed) | R/W | R/W | R | Strict 10-char names is silent footgun | |
| Stockholm | R/W | R/W | R/W | Only format preserving GS/GR/GC/GF annotations | |
| NEXUS | R/W | R/W | -- | MrBayes / PAUP* input | |
| MAF (Multiple Alignment Format) | R/W | R/W | -- | UCSC whole-genome alignments | |
| A2M / A3M | -- (use 'fasta' parser then post-process) | -- | R/W | HMMER (a2m), HHsuite/ColabFold (a3m) | |
| MSF (GCG) | R | -- | -- | GCG legacy | |
| EMBOSS / Mauve XMFA / FASTA-m10 | R | partial | -- | One-way: read-only |
Formats NOT in BioPython (use dedicated tools):
| Format | Tool | Why | |
|---|---|---|---|
| HAL | progressiveCactus, halTools | HDF5-backed multi-genome alignments at TB scale | |
| chain / net | UCSC Kent tools (liftOver, chainNet) | Pairwise genome alignment | |
| AXT | BLASTZ / lastz native | Pairwise alignment blocks | |
| PSL | UCSC Kent tools (pslPretty, blat) | BLAT alignment summary | |
| GFA / rGFA | vg, odgi, pggb, gfatools | Pangenome graph | |
| GAF | vg surject, vg call | Graph alignment format (read-to-graph) |
Recommend Bio.Align (modern API) over Bio.AlignIO (legacy) for new code; it returns Alignment objects with built-in .counts() and .substitutions properties. For multi-gigabyte Stockholm databases such as Pfam-A.full, pyhmmer.easel.MSAFile streams record-by-record where Bio.AlignIO.parse works but at higher per-record cost.
Reading Alignments
"Read an alignment file" -> Parse an alignment file into an alignment object with sequences and metadata accessible.
Goal: Load alignment data from files in various formats (Clustal, PHYLIP, Stockholm, FASTA).
Approach: Use AlignIO.read() for single-alignment files or AlignIO.parse() for files containing multiple alignments.
Single Alignment File
Multiple Alignments in One File
Read as List
Writing Alignments
Goal: Save alignment data to files in standard formats for downstream tools or archival.
Approach: Use AlignIO.write() with the target format specifier, supporting single or multiple alignments and file handles.
Write Single Alignment
Write Multiple Alignments
Write to Handle
Format Conversion
"Convert alignment format" -> Transform an alignment file from one format to another (e.g., Clustal to PHYLIP).
Goal: Convert alignment files between formats for compatibility with different analysis tools.
Approach: Use AlignIO.convert() for direct one-step conversion, or read-modify-write for cases requiring intermediate manipulation.
Direct Conversion (Most Efficient)
With Alphabet Specification
Manual Conversion (When Modification Needed)
Accessing Alignment Data
Goal: Navigate and extract data from alignment objects including sequences, columns, and slices.
Approach: Use iteration, indexing, and column slicing on the alignment object.
Working with Alignment Objects
Get Alignment Properties
Slice Alignments
Creating Alignments Programmatically
Goal: Build an alignment object from sequences defined in code rather than read from a file.
Approach: Construct SeqRecord objects with gap characters and wrap them in a MultipleSeqAlignment.
Format Selection for Downstream Tools
Choosing the output format depends on which downstream tool consumes the alignment:
| Downstream Tool | Required Format | BioPython Format String | |
|---|---|---|---|
| RAxML-NG, IQ-TREE | PHYLIP (relaxed) | 'phylip-relaxed' | |
| MrBayes | NEXUS | 'nexus' | |
| PAUP* | NEXUS or PHYLIP | 'nexus' or 'phylip' | |
| HMMER, Infernal | Stockholm | 'stockholm' | |
| Pfam/Rfam databases | Stockholm | 'stockholm' | |
| PAML/codeml | PHYLIP (sequential) | 'phylip-sequential' | |
| Most tools | FASTA | 'fasta' |
Annotation Preservation
Not all formats support annotations. Converting between formats can silently discard metadata:
| Format | Sequence Annotations | Column Annotations | Secondary Structure | |
|---|---|---|---|---|
| Stockholm | Yes (GS/GR lines) | Yes (GC lines) | Yes (SS_cons) | |
| NEXUS | Partial (SETS block) | Via CHARSET | No | |
| Clustal | No (conservation marks not parsed) | No | No | |
| PHYLIP | No | No | No | |
| FASTA | No | No | No |
Converting Stockholm to FASTA or PHYLIP discards all annotations, secondary structure markup, and per-residue quality scores. If annotations matter, keep a Stockholm master copy.
Format-Specific Notes
PHYLIP Format Pitfalls
PHYLIP has two incompatible variants (interleaved vs sequential) and two name-length modes (strict vs relaxed). Confusing these causes silent data corruption.
Strict PHYLIP truncates sequence names to exactly 10 characters. This can silently merge distinct sequences whose names share a 10-character prefix (e.g., Homo_sapiens_chr1 and Homo_sapiens_chr2 both become Homo_sapie).
PHYLIP-Relaxed Dialect Mismatches Between Tree Tools
Biopython's 'phylip-relaxed' writes a single space between name and sequence. RAxML-NG and IQ-TREE accept this; PhyML rejects sequence names containing colons or parentheses; PAML's codeml expects sequential format with name-truncation behaviour distinct from interleaved. Common silent failures:
| Symptom | Cause | Fix | |
|---|---|---|---|
RAxML-NG: terminating with uncaught exception ... bad alphabet | Stop codons (*) in protein alignment | Replace * with X before writing | |
IQ-TREE: not a valid PHYLIP file | Sequence name contains : (NEXUS-tree-style refs) | Sanitize names: re.sub(r'[():,]', '_', record.id) | |
| PhyML: silently truncated names | Names >100 chars | PhyML truncates without warning at 100 chars in current build | |
codeml: cannot read sequences | Used phylip-relaxed instead of phylip-sequential | codeml requires strict sequential |
Always verify by running the downstream tool's "validate input only" mode (e.g. iqtree2 -s file.phy --check) before committing to a long compute.
MAF Block Coordinate Conventions
UCSC MAF (read via AlignIO.parse(file, 'maf')) returns blocks with per-row annotations:
start(0-based; converts directly to BED but is off-by-one vs GFF)size(length on src strand)strand(+or-)srcSize(length of source chromosome)
For minus-strand rows, start is measured from the END of the source contig: the corresponding plus-strand start is srcSize - start - size. Without this conversion, lifting MAF to genome coordinates places minus-strand blocks at the wrong locus. Reference: UCSC MAF spec at genome.ucsc.edu/FAQ/FAQformat.html#format5.
Stockholm Format Annotations
Stockholm format (used by Pfam, Rfam, HMMER) supports four annotation line types:
| Line Prefix | Scope | Description | Example | |
|---|---|---|---|---|
#=GF | File | Alignment-level metadata (ID, accession, description) | #=GF AC PF00001 | |
#=GC | Column | Per-column annotation (1 char per alignment column) | #=GC SS_cons ..(((...))).. | |
#=GS | Sequence | Per-sequence free text (organism, description) | #=GS seq1 OS Homo sapiens | |
#=GR | Residue | Per-residue annotation (1 char per residue) | #=GR seq1 SS ..HHH..EEE.. |
Common GC annotations: SS_cons (consensus secondary structure), RF (reference coordinates), seq_cons (consensus sequence).
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 reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/bioskills/bio-alignment-alignment-io/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-alignment-io)