pku-yuangroup/openai4s/bio-alignment-msa-parsing
Claude Code and agent skill by pku-yuangroup/openai4s
- community
Checking that the SKILL.md file is still in the repository.
Parse and analyze multiple sequence alignments using Biopython. Extract sequences, identify conserved regions, analyze gaps, work with annotations, and manipulate alignment data for downstream analysis. Use when parsing or manipulating multiple sequence alignments.
Install
npx vskill@latest install pku-yuangroup/openai4s/bio-alignment-msa-parsingSKILL.md
The same SKILL.md was published earlier as pku-yuangroup/openai4s/bio-alignment-msa-parsing.
Version Compatibility
Reference examples tested with: BioPython 1.83+, numpy 1.26+
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.
MSA Parsing and Analysis
Parse multiple sequence alignments to extract information, analyze content, and prepare for downstream analysis.
Required Import
Goal: Load modules for parsing, analyzing, and manipulating multiple sequence alignments.
Approach: Import AlignIO for reading, Counter for column analysis, and alignment classes for constructing modified alignments.
Optional for streaming and Easel-based weighting:
Loading Alignments
Goal: Read an MSA file and inspect its dimensions.
Approach: Use AlignIO.read() specifying the file and format.
Extracting Sequence Information
Get All Sequence IDs
Get Sequences as Strings
Get Sequence by ID
Access Descriptions and Annotations
Column-wise Analysis
Goal: Analyze alignment content column by column to assess composition, conservation, and variability.
Approach: Use column indexing (alignment[:, idx]) and Counter to examine character frequencies at each position.
Get Single Column
API note: Bio.AlignIO returns MultipleSeqAlignment objects whose [:, idx] returns a plain str; [:, start:end] returns another MultipleSeqAlignment. The newer Bio.Align.Alignment (from Align.read / Align.parse) uses numpy-backed slicing -- verify with type(alignment[:, 0]) before assuming string methods work. For numpy-array access to the full alignment, use np.array(alignment).
Iterate and Count Columns
Find Conserved Positions
Gap Analysis
Goal: Quantify gap distribution across sequences and columns to identify problematic regions or sequences.
Approach: Count gap characters per sequence and per column, then identify positions exceeding a gap fraction threshold.
Count Gaps Per Sequence
Count Gaps Per Column
Find Gappy Columns
Remove Gappy Columns
Alignment Trimming
Trimming controversy and tool selection (ClipKIT, trimAl, BMGE, Divvier, HMMcleaner, Noisy) is the subject of a dedicated skill. Use this short decision matrix for routing:
| Goal | First-line tool | |
|---|---|---|
| Phylogenetic-tree input | ClipKIT kpic-smart-gap (Steenwyk et al 2020 PLOS Bio) | |
| HMM profile building | trimAl -gappyout (Capella-Gutierrez et al 2009 Bioinf) | |
| Selection / dN/dS input | Avoid aggressive trimming; use TCS / GUIDANCE2 column masking | |
| Deep prokaryotic phylogenomics | BMGE (Criscuolo & Gribaldo 2010 BMC Evol Biol) | |
| Preserve column-mapping for residue-level analysis | trimAl -colnumbering |
See alignment/alignment-trimming for full mode comparisons, decision trees, and runnable examples.
Gap Handling for Phylogenetics
How gaps are treated in downstream phylogenetic analysis significantly affects tree topology:
| Treatment | Method | Tradeoff | |
|---|---|---|---|
| Missing data (default) | Gaps = unknown character | Most common; can be statistically inconsistent under ML | |
| Fifth state | Gap = 5th nucleotide | Biologically problematic (gaps of different lengths treated equally) | |
| Simple indel coding | Each unique indel coded as binary character | Most biologically realistic; adds phylogenetic signal |
For slow- to mid-rate datasets where indels are phylogenetically informative, prefer SIC indel coding or fifth-state treatment; for rapidly-evolving datasets (intra-species, ITS regions, retroelement-rich plant genomes), default to missing-data treatment because gap homology is unreliable. Run a sensitivity analysis comparing both treatments before drawing topological conclusions.
Identifying Unreliable Alignment Regions
Columns exhibiting both high gap fraction AND low conservation are the strongest indicators of alignment uncertainty. These often reflect guide tree artifacts rather than true evolutionary events. Before phylogenetic analysis:
- Flag columns with gap fraction >50%, which may be alignment artifacts
- Check if gappy regions coincide with insertions in a single divergent sequence (remove that sequence and re-align)
- For critical analyses, run GUIDANCE2 or MUSCLE5 ensemble to get per-column confidence scores; mask columns below the reliability threshold (default: 0.93 for GUIDANCE2)
Consensus Sequence
"Get consensus sequence" -> Derive a single representative sequence from an MSA based on majority-rule voting at each column.
Goal: Generate a consensus sequence from the alignment using a frequency threshold.
Approach: At each column, select the most common non-gap character if it exceeds the threshold; otherwise mark as ambiguous.
Simple Majority Consensus
Note on Bio.Align.AlignInfo
The AlignInfo.SummaryInfo class is deprecated in recent Biopython versions. The custom consensus_sequence() function above is the recommended approach. When deprecation warnings appear from AlignInfo, callers should switch to the custom implementation.
Extracting Regions
Slice by Column Range
Slice by Sequence Range
Extract Ungapped Regions from Reference
Sequence Filtering
Goal: Subset an alignment to retain only sequences matching specific criteria (ID pattern, gap content, uniqueness).
Approach: Iterate over alignment records, apply filter conditions, and reconstruct a new MultipleSeqAlignment from matching records.
Working with Annotations
Stockholm-derived alignments expose secondary-structure markup, per-column GC/GR annotations, and per-sequence metadata via record.annotations, record.letter_annotations, and alignment.column_annotations. See usage-guide.md "Working with Annotations" for the full access pattern.
Position Mapping
Goal: Convert between alignment column coordinates and ungapped sequence coordinates.
Approach: For one-off lookups, walk the sequence tracking gap characters. For repeated queries on the same sequence, vectorize with numpy.cumsum over a gap-mask -- O(L) preprocessing, O(1) lookups.
Vectorized Coordinate Mapping (Recommended)
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 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-msa-parsing/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-msa-parsing)