This skill focuses on parsing and analyzing multiple sequence alignments (MSAs). It covers extracting information, analyzing gaps and conservation, filtering sequences, and preparing alignments for downstream analysis like phylogenetics or structure prediction.
pip install biopython numpy
# Optional for Pfam-scale streaming:
pip install pyhmmer
Tell your AI agent what you want to do: - "Find all the fully conserved positions in this alignment" - "Remove sequences with more than 10% gaps" - "Generate a consensus sequence from this alignment"
"Show me the composition of each column in the alignment"
"Find positions that are conserved in at least 80% of sequences"
"Count the gaps in each sequence"
"Remove columns with more than 50% gaps"
"Filter out sequences with too many gaps"
"Remove duplicate sequences from the alignment"
"Get the sequence for species_A from this alignment"
"Extract columns 100-200 from the alignment"
"List all sequence IDs in the alignment"
"Generate a consensus sequence with 70% threshold"
"Find the most conserved regions in this alignment"
"What is the consensus at each position?"
| Term | Description |
|---|---|
| Column | Vertical slice (same position across all sequences) |
| Conservation | Fraction of sequences with same residue at a position |
| Consensus | Most common character at each position |
| Gap | Missing data represented by '-' |
Stockholm-derived alignments expose secondary-structure markup, GC/GR per-column annotations, and per-sequence metadata via record.annotations, record.letter_annotations, and alignment.column_annotations:
from Bio import AlignIO
alignment = AlignIO.read('pfam.sto', 'stockholm')
for record in alignment:
if 'secondary_structure' in record.letter_annotations:
print(record.id, record.letter_annotations['secondary_structure'])
ss_cons = alignment.column_annotations.get('secondary_structure')
GC SS_cons (consensus secondary structure), GC RF (reference coordinates), and GS metadata (organism, taxonomy) survive read/write through the 'stockholm' format string but are silently discarded when writing to FASTA, PHYLIP, or NEXUS. Keep a Stockholm master copy if annotations matter for downstream analysis.
kpic-smart-gap mode) over traditional removal tools; aggressive trimming (>20-30% of sites) can hurt tree quality