scikit-bio
Skill22 starsChanged 9 months agoMITView on GitHub
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.
- Installs packages
We split this skill into the rules it gives an agent
13 rules. 0 are common, 7 are distinctive, and 6 are very specific to this project.
0
Common
Most of the 10 edited versions we read keep these.
7
Distinctive
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 32
Instead of using raw strings, scikit-bio uses typed objects (DNA, RNA, Protein).
- Distinctive: line 82
Use Typed Sequences: - Always use DNA, RNA, or Protein instead of generic Sequence to enable alphabet-specific methods.
- Distinctive: line 83
Set Metadata: - Use the metadata and positional_metadata (for quality scores) attributes to keep data self-contained.
- Very specific: line 84
Check Alphabet: - Use .is_valid() when importing data from untrusted sources to catch non-IUPAC characters.
- Very specific: line 85
Project Distance Matrices: - Use pcoa() to visualize high-dimensional community data.
- Distinctive: line 86
Specify Reference for UniFrac: - When calculating UniFrac diversity, ensure your phylogenetic tree contains all taxa present in your …
- Very specific: line 87
Validate Trees: - Use skbio.tree.TreeNode for tree manipulations as it provides robust traversal methods.
- Distinctive: line 91
Mix Sequence Types: - Don't try to align DNA with RNA objects.
- Distinctive: line 92
Ignore Quality Scores: - If you have FASTQ data, store Phred scores in positional_metadata.
- Very specific: line 93
Manually Calculate Distance: - Don't use raw NumPy for biological distances.
- Distinctive: line 94
Forget ID Matching: - When performing ordination or PERMANOVA, ensure IDs in your distance matrix and metadata mapping match exactly.
- Very specific: line 289
When calculating diversity for many samples, pass the entire 2D array to beta.pw_distances instead of looping through pairs.
- Very specific: line 293
Use tree.preorder() or tree.postorder() instead of manual recursion for much better performance on large (10,000+ tip) trees.
“Common” is measured: kept by at least 6 in 10 of the 10 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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
pip install scikit-bioStandard Imports
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 pcoaBasic Pattern - Sequence Manipulation
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 alphabetCritical 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.TreeNodefor 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.betato 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)
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
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)
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)
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
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)
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.samplesCommunity Testing (PERMANOVA)
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
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/Plotly2. Sequence QC and Filtering
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_seqs3. Phylogenetic Distance Calculation
def get_tip_distances(tree):
"""Returns a distance matrix of all tips in a tree."""
dm = tree.tip_tip_distances()
return dmPerformance 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.
# ✅ 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.
# ❌ 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 anythingscikit-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.
Other versions10 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 10
- wu-yc/LabClaw★ 1.1ksame name
- LeonChaoX/qinyan-academic-skills★ 910same name
- jaechang-hits/SciAgent-Skills★ 383same name
- qinyan-ai/qinyan-academic-skills★ 80same name
- BrightGold70/skills★ 1same name
- Luooops/skills★ 1same name
- uppifyagency/boilerplate-saas-2026★ 1same name
- yf8578/claude-skills-collection★ 1same name
- davidanthonyn/claude-skills★ 0same name
- patoangolano/bio-stack★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
Used alongsideProjects with it also use usfiscaldata, benchling-integration and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
yf8578Skillusfiscaldata
Query the U.S. Treasury Fiscal Data API for federal financial data including national debt, government spending, revenue, interest rates, exchange rates, and savings bonds. Access 54 datasets and 182 data tables with no API key required. Use when working with U.S. federal fiscal data, national debt tracking (Debt to the Penny), Daily Treasury Statements, Monthly Treasury Statements, Treasury securities auctions, interest rates on Treasury securities, foreign exchange rates, savings bonds, or any U.S. government financial statistics.
Also in 6 projects that use this
garri333Skillbenchling-integration
Benchling R&D platform integration. Access registry (DNA, proteins), inventory, ELN entries, workflows via API, build Benchling Apps, query Data Warehouse, for lab data management automation.
Also in 9 projects that use this
garri333Skilletetoolkit
Phylogenetic tree toolkit (ETE). Tree manipulation (Newick/NHX), evolutionary event detection, orthology/paralogy, NCBI taxonomy, visualization (PDF/SVG), for phylogenomics.
Also in 9 projects that use this
- +9 more from garri333
In this repository69 other files it gives its agents.
- aseSkill
- astropySkill
- biopythonSkill
- chempySkill
- cobrapySkill
- dask-optimizationSkill
- daskSkill
- dowhySkill
- duckdbSkill
- example-skillSkill
- fastapi-streamlitSkill
- geopandasSkill
- gmsh-meshioSkill
- h5pySkill
- jax-pdeSkill
- jaxSkill
- lifelinesSkill
- matplotlib-proSkill
- matplotlibSkill
- mdanalysisSkill
- mneSkill
- networkxSkill
- numbaSkill
- numpy-low-levelSkill
- numpySkill
- openbabelSkill
- opencvSkill
- ortoolsSkill
- pandas-performanceSkill
- pennylaneSkill
- photutilsSkill
- plotlySkill
- polarsSkill
- prodySkill
- pydicomSkill
- pymcSkill
- pyomoSkill
- pyprojSkill
- pysamSkill
- pyscfSkill
- pytorch-deploymentSkill
- pytorch-geometricSkill
- pytorch-researchSkill
- pytorchSkill
- qiskit-hardwareSkill
- qiskitSkill
- qutipSkill
- rasterioSkill
- rdkitSkill
- scanpySkill
- scikit-imageSkill
- scikit-learnSkill
- scikit-videoSkill
- scipySkill
- seabornSkill
- shapelySkill
- simpySkill
- sklearn-advancedSkill
- sklearn-explainabilitySkill
- sktime-tsfreshSkill
- The first 60 shown.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

