scikit-bio
Library for bioinformatics and community ecology statistics. Provides data structures and algorithms for sequences, alignments, phylogenetics, and diversity analysis. Essential for microbiome research and ecological data science. Use for alpha/beta diversity metrics, ordination (PCoA), phylogenetic trees, sequence manipulation (DNA/RNA/Protein), distance matrices, PERMANOVA, and community ecology analysis.
Best use case
scikit-bio is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Library for bioinformatics and community ecology statistics. Provides data structures and algorithms for sequences, alignments, phylogenetics, and diversity analysis. Essential for microbiome research and ecological data science. Use for alpha/beta diversity metrics, ordination (PCoA), phylogenetic trees, sequence manipulation (DNA/RNA/Protein), distance matrices, PERMANOVA, and community ecology analysis.
Teams using scikit-bio should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/scikit-bio/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How scikit-bio Compares
| Feature / Agent | scikit-bio | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Library for bioinformatics and community ecology statistics. Provides data structures and algorithms for sequences, alignments, phylogenetics, and diversity analysis. Essential for microbiome research and ecological data science. Use for alpha/beta diversity metrics, ordination (PCoA), phylogenetic trees, sequence manipulation (DNA/RNA/Protein), distance matrices, PERMANOVA, and community ecology analysis.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# scikit-bio - Bioinformatics and Ecology
scikit-bio provides the data structures and statistical methods needed for rigorous biological analysis. It excels in calculating alpha/beta diversity, performing ordination (PCoA), and handling complex phylogenetic trees.
## When to Use
- Analyzing microbiome data (taxonomic composition, community structure).
- Calculating ecological diversity metrics (Shannon, Simpson, UniFrac).
- Performing ordination for visualization (PCoA, DCA).
- High-level sequence manipulation (DNA, RNA, Protein with metadata).
- Reading and writing phylogenetic trees (Newick format).
- Pairwise and multiple sequence alignment analysis.
- Statistical testing of community differences (PERMANOVA, ANOSIM).
## Reference Documentation
**Official docs**: http://scikit-bio.org/
**Tutorials**: http://scikit-bio.org/docs/latest/
**Search patterns**: `skbio.sequence`, `skbio.stats.distance`, `skbio.diversity`, `skbio.stats.ordination`
## Core Principles
### Grammar of Biological Sequences
Instead of using raw strings, scikit-bio uses typed objects (DNA, RNA, Protein). These objects know their alphabet, can handle quality scores (Phred), and support biological operations (transcription, translation).
### Distance Matrices
Microbiome research often boils down to comparing samples. The DistanceMatrix object is central, allowing for easy indexing, sub-setting, and statistical testing (e.g., PERMANOVA).
### Diversity Metrics
Provides a standardized implementation of hundreds of diversity metrics used in ecology, ensuring reproducibility across studies.
## Quick Reference
### Installation
```bash
pip install scikit-bio
```
### Standard Imports
```python
import skbio
import numpy as np
import pandas as pd
from skbio import DNA, RNA, Protein, Sequence
from skbio.stats.distance import DistanceMatrix
from skbio.diversity import alpha, beta
from skbio.stats.ordination import pcoa
```
### Basic Pattern - Sequence Manipulation
```python
from skbio import DNA
# 1. Create a sequence with metadata
seq = DNA("ACC--GTT", metadata={'id': 'sample1', 'desc': 'gene A'})
# 2. Biological operations
rc = seq.reverse_complement()
degapped = seq.degap()
# 3. Validation
print(f"Is valid? {seq.is_valid()}") # Checks against DNA alphabet
```
## Critical Rules
### ✅ DO
- **Use Typed Sequences** - Always use DNA, RNA, or Protein instead of generic Sequence to enable alphabet-specific methods.
- **Set Metadata** - Use the metadata and positional_metadata (for quality scores) attributes to keep data self-contained.
- **Check Alphabet** - Use `.is_valid()` when importing data from untrusted sources to catch non-IUPAC characters.
- **Project Distance Matrices** - Use `pcoa()` to visualize high-dimensional community data.
- **Specify Reference for UniFrac** - When calculating UniFrac diversity, ensure your phylogenetic tree contains all taxa present in your abundance table.
- **Validate Trees** - Use `skbio.tree.TreeNode` for tree manipulations as it provides robust traversal methods.
### ❌ DON'T
- **Mix Sequence Types** - Don't try to align DNA with RNA objects.
- **Ignore Quality Scores** - If you have FASTQ data, store Phred scores in positional_metadata.
- **Manually Calculate Distance** - Don't use raw NumPy for biological distances; use `skbio.diversity.beta` to access UniFrac or Bray-Curtis.
- **Forget ID Matching** - When performing ordination or PERMANOVA, ensure IDs in your distance matrix and metadata mapping match exactly.
## Anti-Patterns (NEVER)
```python
from skbio import DNA
# ❌ BAD: Manual reverse complement with string logic
rc_str = seq_str[::-1].replace('A', 't').replace('T', 'a')... # Fragile
# ✅ GOOD: Built-in validated method
rc_seq = DNA(seq_str).reverse_complement()
# ❌ BAD: Using raw lists for community analysis
# data = [[1, 0, 5], [2, 1, 0]]
# dist = manual_bray_curtis(data)
# ✅ GOOD: Using DistanceMatrix
from skbio.stats.distance import DistanceMatrix
dm = DistanceMatrix(matrix_data, ids=['S1', 'S2', 'S3'])
# ❌ BAD: Stripping metadata to run scikit-learn
# vals = seq.values # Metadata lost!
# ✅ GOOD: Process within skbio or use standard IO
seq.write('output.fasta')
```
## Sequence Analysis (skbio.sequence)
### Advanced Sequence Operations
```python
from skbio import DNA, Protein
# Sequence with quality scores
seq = DNA("ACGT", positional_metadata={'quality': [30, 35, 40, 20]})
# Slicing preserves metadata
sub = seq[1:3]
print(sub.positional_metadata) # {'quality': [35, 40]}
# K-mer frequencies
freqs = seq.kmer_frequencies(k=2)
# Translation (DNA -> Protein)
protein = DNA("ATGCGA").translate()
```
## Diversity Analysis (skbio.diversity)
### Alpha Diversity (Within a sample)
```python
from skbio.diversity import alpha
counts = [10, 0, 5, 2, 20] # Species abundances
otus = ['OTU1', 'OTU2', 'OTU3', 'OTU4', 'OTU5']
shannon = alpha.shannon(counts)
simpson = alpha.simpson(counts)
observed_otus = alpha.observed_otus(counts)
print(f"Shannon Index: {shannon:.3f}")
```
### Beta Diversity (Between samples)
```python
from skbio.diversity import beta
import numpy as np
# Abundance table (samples x taxa)
data = np.array([[10, 20, 0],
[5, 15, 2],
[0, 1, 30]])
ids = ['Sample1', 'Sample2', 'Sample3']
# Bray-Curtis distance
bc_dm = beta.pw_distances(data, ids=ids, metric='braycurtis')
# Weighted UniFrac (Requires a tree)
# unifrac_dm = beta.weighted_unifrac(data, otu_ids, tree)
```
## Phylogenetics (skbio.tree)
### Handling Trees
```python
from skbio import TreeNode
from io import StringIO
# Load Newick tree
tree_str = "((A:0.1, B:0.2)C:0.3, D:0.4)E;"
tree = TreeNode.read(StringIO(tree_str))
# Traverse
for node in tree.tips():
print(f"Leaf: {node.name}, dist: {node.length}")
# Find Lowest Common Ancestor
lca = tree.find_lca(['A', 'B'])
print(f"LCA of A and B is {lca.name}")
# Rooting
tree.root_at('D')
```
## Statistics and Ordination
### PCoA (Principal Coordinates Analysis)
```python
from skbio.stats.ordination import pcoa
from skbio.stats.distance import DistanceMatrix
# Create DM
dm = DistanceMatrix([[0, 0.5, 0.8], [0.5, 0, 0.2], [0.8, 0.2, 0]],
ids=['A', 'B', 'C'])
# Perform PCoA
results = pcoa(dm)
# View proportion of variance explained
print(results.proportion_explained)
# Access coordinates for plotting
coords = results.samples
```
### Community Testing (PERMANOVA)
```python
from skbio.stats.distance import permanova
# metadata linking IDs to groups
metadata = pd.DataFrame({
'BodySite': ['Gut', 'Gut', 'Skin', 'Skin']},
index=['S1', 'S2', 'S3', 'S4'])
# Assuming dm is a DistanceMatrix of S1..S4
# results = permanova(dm, metadata, column='BodySite', permutations=999)
# print(results['p-value'])
```
## Practical Workflows
### 1. Microbiome Distance Visualization
```python
def plot_microbiome_pcoa(abundance_df, metadata_df, group_col):
"""Full workflow: Abundance -> Distance -> PCoA -> Table."""
from skbio.diversity import beta
from skbio.stats.ordination import pcoa
# 1. Calculate Bray-Curtis distance
dm = beta.pw_distances(abundance_df.values, ids=abundance_df.index, metric='braycurtis')
# 2. PCoA
pc = pcoa(dm)
# 3. Merge with metadata for plotting
plot_data = pc.samples[['PC1', 'PC2']].join(metadata_df)
return plot_data # Ready for Seaborn/Plotly
```
### 2. Sequence QC and Filtering
```python
def filter_low_quality_sequences(sequences, min_avg_qual=30):
"""Filters DNA sequences based on Phred scores."""
valid_seqs = []
for s in sequences:
# Assuming quality is in positional_metadata
avg_q = np.mean(s.positional_metadata['quality'])
if avg_q >= min_avg_qual:
valid_seqs.append(s)
return valid_seqs
```
### 3. Phylogenetic Distance Calculation
```python
def get_tip_distances(tree):
"""Returns a distance matrix of all tips in a tree."""
dm = tree.tip_tip_distances()
return dm
```
## Performance Optimization
### Vectorized Diversity
When calculating diversity for many samples, pass the entire 2D array to `beta.pw_distances` instead of looping through pairs.
### Tree Traversal
Use `tree.preorder()` or `tree.postorder()` instead of manual recursion for much better performance on large (10,000+ tip) trees.
## Common Pitfalls and Solutions
### The "Missing ID" in Distance Matrix
PERMANOVA and PCoA will fail if your metadata index and DistanceMatrix IDs don't match.
```python
# ✅ Solution: Ensure alignment
common_ids = set(dm.ids).intersection(metadata.index)
dm_sub = dm.filter(common_ids)
metadata_sub = metadata.loc[list(common_ids)]
```
### UniFrac Memory Usage
UniFrac calculation can be memory-intensive. For massive datasets, consider using the `skbio.diversity.beta.unweighted_unifrac` optimized versions or external tools like Unifrac-Binaries.
### IUPAC Ambiguity
Standard DNA objects don't allow arbitrary characters.
```python
# ❌ Problem: DNA("ACGN") raises error if 'N' isn't handled
# ✅ Solution: scikit-bio DNA supports IUPAC (N, R, Y, etc.) by default.
# But if you have non-standard characters:
from skbio import Sequence
custom = Sequence("ACG-X") # Generic sequence permits anything
```
scikit-bio is the mathematical heart of modern microbiome and evolutionary research. By enforcing strict biological typing and providing validated ecological metrics, it ensures that your biological insights are grounded in statistical rigor.Related Skills
scikit-video
Video processing library for scientists. Provides easy access to video files using FFmpeg, motion estimation algorithms, and video quality metrics. Built on NumPy and designed for high-performance research in computer vision and image sequence analysis. Use when working with video files, motion estimation, video quality assessment (VQA), FFmpeg, temporal image data, video codecs, YUV data, or scientific video recordings.
scikit-learn
The industry standard library for machine learning in Python. Provides simple and efficient tools for predictive data analysis, covering classification, regression, clustering, dimensionality reduction, model selection, and preprocessing.
scikit-image
A collection of algorithms for image processing in Python. Built on NumPy, SciPy, and Cython. It focuses on scientific image analysis including segmentation, geometric transformations, color space manipulation, analysis, and filtering.
xgboost-lightgbm
Industry-standard gradient boosting libraries for tabular data and structured datasets. XGBoost and LightGBM excel at classification and regression tasks on tables, CSVs, and databases. Use when working with tabular machine learning, gradient boosting trees, Kaggle competitions, feature importance analysis, hyperparameter tuning, or when you need state-of-the-art performance on structured data.
xarray
N-dimensional labeled arrays and datasets in Python. Built on top of NumPy and Dask. It introduces labels in the form of dimensions, coordinates, and attributes on top of raw NumPy-like arrays, making data analysis in physical sciences more intuitive and less error-prone. Use for working with multi-dimensional scientific data, NetCDF/GRIB/Zarr files, climate/weather/oceanographic datasets, remote sensing, geospatial imaging, large out-of-memory datasets with Dask, and labeled array operations.
transformers
State-of-the-art Machine Learning for PyTorch, TensorFlow, and JAX. Provides thousands of pretrained models to perform tasks on different modalities such as text, vision, and audio. The industry standard for Large Language Models (LLMs) and foundation models in science.
tqdm
A fast, extensible progress bar for Python and CLI. Instantly makes your loops show a smart progress meter with ETA, iterations per second, and customizable statistics. Minimal overhead. Use for monitoring long-running loops, simulations, data processing, ML training, file downloads, I/O operations, command-line tools, pandas operations, parallel tasks, and nested progress bars.
tensorflow
Comprehensive deep learning framework for building, training, and deploying neural networks. TensorFlow provides tf.keras high-level API for model construction, tf.data for efficient data pipelines, and tf.function for graph-mode optimization. Use when working with: neural network training and inference, image classification/detection/segmentation, NLP/text processing with embeddings or transformers, time series forecasting, generative models (VAE, GAN), transfer learning with pretrained models, custom training loops with GradientTape, GPU/TPU accelerated computation, or any deep learning task.
sympy
Comprehensive guide for SymPy - Python library for symbolic mathematics. Use for symbolic expressions, calculus (derivatives, integrals, limits, series), equation solving (algebraic, differential, systems), linear algebra, simplification, matrix operations, special functions, code generation, and mathematical proofs. Essential for analytical mathematics and computer algebra.
sunpy
The community-developed free and open-source software package for solar physics. Provides tools for data search and download, coordinate transformations specific to solar physics, and powerful image processing through the Map object. Use when working with solar data, solar images (EUV, magnetograms, white light), solar coordinates (Helioprojective, Heliographic), Fido data search, solar time series, differential rotation, limb fitting, or multi-instrument solar analysis (AIA, HMI, GOES).
statsmodels
Advanced statistical modeling and hypothesis testing. Complementary to SciPy's stats module, it provides classes and functions for the estimation of many different statistical models, as well as for conducting statistical tests and statistical data exploration. Use for linear regression, GLM, time series analysis, ANOVA, survival analysis, causal inference, and statistical hypothesis testing. Load when working with OLS, WLS, logistic regression, Poisson regression, ARIMA, SARIMAX, statistical diagnostics, p-values, confidence intervals, or R-style statistical analysis.
spacy-nltk
Natural Language Processing for text analysis, corpus linguistics, and production NLP pipelines. spaCy provides fast production-grade tokenization, POS tagging, NER, dependency parsing, and custom model training. NLTK provides classical corpus linguistics, linguistic analysis, VADER sentiment, collocation analysis, and access to standard linguistic corpora. Use when: processing and analyzing text data, extracting named entities (people, orgs, locations, dates), dependency parsing and syntactic analysis, building text classification pipelines, performing corpus-level linguistic analysis (frequency, collocations, readability), sentiment analysis, lemmatization and stemming, working with multilingual text, training custom NER or text classifiers, or any task requiring structured understanding of natural language beyond simple string operations.