scikit-bio
Biological data toolkit. Sequence analysis, alignments, phylogenetic trees, diversity metrics (alpha/beta, UniFrac), ordination (PCoA), PERMANOVA, FASTA/Newick I/O, for microbiome analysis.
By k-dense-ai · 1,452 installs
npx skills add k-dense-ai/scientific-agent-skills --skill scikit-bio
Source repository · Upstream listing
scikit bio
Overview
Targets scikit bio 0.7.4. Use it for sequence manipulation, alignment, phylogenetics, microbial ecology, and multivariate statistics. Native tests exercise small synthetic fixtures; examples with filenames or undefined inputs are workflow templates. See [review evidence and boundaries](references/review.md).
When to Use This Skill
This skill should be used when the user:
Works with biological sequences (DNA, RNA, protein)
Needs to read/write biological file formats (FASTA, FASTQ, GenBank, Newick, BIOM, etc.)
Performs sequence alignments or searches for motifs
Constructs or analyzes phylogenetic trees
Calculates diversity metrics (alpha/beta diversity, UniFrac distances)
Performs ordination analysis (PCoA, CCA, RDA)
Runs statistical tests on biological/ecological data (PERMANOVA, ANOSIM, Mantel)
Analyzes microbiome or community ecology data
Works with protein embeddings from language models
Needs to manipulate biological data tables
Core Capabilities
1. Sequence Manipulation
Work with biological sequences using specialized classes for DNA, RNA, and protein data.
Key operations:
Read/write sequences from FASTA, FASTQ, GenBank, EMBL formats
Sequence slicing, concatenation, and searching
Reverse complement, transcription (DNA→RNA), and translation (RNA→protein)
Find motifs and patterns using regex
Calculate distances (Hamming, k mer based)
Handle sequence quality scores and metadata
Common patterns:
Important notes:
Use DNA , RNA , Protein classes for grammared sequences with validation
Use Sequence class for generic sequences without alphabet restrictions
FASTQ quality scores load into positional metadata; specify the known phred offset=33 or variant (do not infer encoding from the filename). Translation needs an explicit genetic code/frame and a decision about incomplete codons.
Metadata types: sequence level (ID, description), positional (per base), interval (regions/features)
2. Sequence Alignment
Perform pairwise and multiple sequence alignments using the pair align engine (introduced in scikit bio 0.7.0), a versatile and efficient dynamic programming aligner.
Key capabilities:
Global, local, and semi global alignment (free ends configurable) in one function
Convenience wrappers pair align nucl (BLASTN like) and pair align prot (BLASTP like)
Configurable scoring: match/mismatch tuple or named substitution matrix; linear or affine gap penalties
PairAlignPath results carry CIGAR strings and convert to aligned sequences
Multiple sequence alignment with multi align nucl / multi align prot (0.7.4); storage and manipulation with TabularMSA
Common patterns:
Important notes:
pair align replaces the removed SSW wrapper ( local pairwise align ssw , StripedSmithWaterman ) and the deprecated pure Python aligners ( global pairwise align , local pairwise align nucleotide , etc.)
The result is a PairAlignResult that also unpacks as score, paths, matrices (use keep matrices=True to retain the DP matrix)
sub score accepts a (match, mismatch) tuple or a matrix name (e.g., 'NUC.4.4' , 'BLOSUM62' ); gap cost accepts a single number (linear) or (open, extend) tuple (affine)
mode="global" defaults to free terminal gaps (overlap); use free ends=False for fully penalized global alignment. Affine gap cost is open + length × extend. Wrapper scoring resembles BLAST, but is not a BLAST search or E value.
Parse external CIGAR strings with PairAlignPath.from cigar('1I8M2D5M2I') ; score an existing alignment with align score(...) and build a distance matrix from an MSA with align dists(...)
3. Phylogenetic Trees
Construct, manipulate, and analyze phylogenetic trees representing evolutionary relationships.
Key capabilities:
Tree construction from distance matrices (UPGMA/WPGMA, Neighbor Joining, GME, BME)
Tree rearrangement with nearest neighbor interchange ( nni )
Tree manipulation (pruning, rerooting, traversal)
Distance calculations (patristic via cophenet , Robinson Foulds via compare rfd )
ASCII visualization
Newick format I/O
Common patterns:
Important notes:
Use nj() for neighbor joining (classic phylogenetic method)
Use upgma() for UPGMA/WPGMA (assumes molecular clock)
GME and BME are highly scalable for large trees; refine topology with nni()
cophenet() (formerly tip tip distances ) returns the patristic distance matrix; compare rfd() is the Robinson Foulds method ( compare wrfd / compare cophenet for weighted/cophenetic variants)
lca() is the lowest common ancestor; lowest common ancestor remains as an alias
NJ/GME/BME produce unrooted trees and clamp negative branches by default; record this choice. Rooting and sequence distance models need scientific justification. RF comparisons must use a declared shared taxon set and rooting convention.
4. Diversity Analysis
Calculate alpha and beta diversity metrics for microbial ecology and community analysis.
Key capabilities:
Alpha diversity: richness ( sobs , observed features , chao1 , ace ), Shannon, Simpson, Hill numbers ( hill ), Faith's PD ( faith pd ), generalized PD ( phydiv ), Pielou's evenness
Beta diversity: Bray Curtis, Jaccard, weighted/unweighted UniFrac, Euclidean distances
Phylogenetic diversity metrics (require tree input)
Rarefaction and subsampling
Integration with ordination and statistical tests
Common patterns:
Important notes:
Keep finite, nonnegative raw counts for count based estimators and rarefaction; never manufacture counts by scaling proportions. Shannon/Bray Curtis can accept nonnegative abundances, but normalization changes the scientific question. Reject empty samples explicitly.
The phylogenetic metric argument is taxa= (renamed from otu ids in 0.6.0; the old name is a deprecated alias); observed otus is now observed features (or sobs )
counts matrix may be any table like input (NumPy array, pandas/polars DataFrame, BIOM Table , or AnnData) via the dispatch system
Phylogenetic metrics (Faith's PD, UniFrac) require a rooted tree with branch lengths and unique ordered taxa to tip mapping
block beta diversity() supports block decomposition; pass a SciPy metric callable (e.g. scipy.spatial.distance.braycurtis ) instead of its string for that path. Deprecated partial beta diversity() fills uncomputed pairs with zero; never send that matrix to PCoA or statistical tests.
Alpha diversity returns a pandas.Series , beta diversity returns a DistanceMatrix
5. Ordination Methods
Reduce high dimensional biological data to visualizable lower dimensional spaces.
Key capabilities:
PCoA (Principal Coordinate Analysis) from distance matrices
CA (Correspondence Analysis) for contingency tables
CCA (Canonical Correspondence Analysis) with environmental constraints
RDA (Redundancy Analysis) for linear relationships
Biplot projection for feature interpretation
Common patterns:
Important notes:
PCoA accepts a valid distance matrix; non Euclidean dissimilarities may have negative eigenvalues. Inspect warnings and retained variance; a 2D plot is not the full distance geometry. dimensions accepts a count or a float in (0, 1] (variance fraction).
OrdinationResults exposes pandas based attributes: samples , features , eigvals , proportion explained , biplot scores , sample constraints
CCA describes constrained associations, not causal environmental drivers. Align sample IDs first; avoid rank deficient or overfit constraints.
OrdinationResults.plot() produces a matplotlib figure; results also integrate with seaborn/plotly
6. Statistical Testing
Perform hypothesis tests specific to ecological and biological data.
Key capabilities:
PERMANOVA: test group differences using distance matrices
ANOSIM: alternative test for group differences
PERMDISP: test homogeneity of group dispersions
Mantel test: correlation between distance matrices
Bioenv: find environmental variables correlated with distances
Differential abundance: ancom , dirmult ttest , and dirmult lme (longitudinal mixed effects) in skbio.stats.composition
Common patterns:
Important notes:
Permutation tests provide non parametric significance testing
Choose permutations for the required precision; with 999 permutations the minimum p value is 0.001. Record seed and versions. Built in grouping tests use unrestricted permutations: repeated measures/blocks require a design aware method outside this recipe.
PERMANOVA consumes the full distance matrix, not plotted PCoA axes. With permdisp , use dimensions=0 for all axes; its default 10 fails when n < 10 in 0.7.4. It is sensitive to dispersion; inspect PERMDISP and sample sizes. A nonsignificant dispersion test does not prove equal dispersions.
Mantel tests assess two matrix association, not causality or adjustment for a third matrix. scikit bio has no partial Mantel argument. Align IDs and justify exchangeability; ANOSIM/Mantel do not repair confounding.
Supply differential abundance tests with raw counts, not pre normalized proportions, to preserve magnitude information
7. File I/O and Format Conversion
Read and write 19+ biological file formats with automatic format detection.
Supported formats:
Sequences: FASTA, FASTQ, GenBank, EMBL, QSeq
Alignments: Clustal, PHYLIP, Stockholm
Trees: Newick
Tables: BIOM 2.1 HDF5 through format="biom" ; use biom.load table for legacy JSON
Distances: delimited square matrices
Analysis: BLAST+6/7, GFF3, Ordination results
Metadata: use pandas TSV/CSV readers, then explicitly validate IDs, missingness, and types
Common patterns:
Important notes:
Use generators for large files to avoid memory issues
Format can be auto detected when into parameter specified
Some objects can be written to multiple formats
For file handles/pipes, specify the format and object/constructor; verify=False only skips format verification and is not a general validation bypass.
8. Distance Matrices
Create and manipulate distance/dissimilarity matrices with statistical methods.
Key capabilities:
Store symmetric ( DistanceMatrix , hollow diagonal) or general pairwise ( PairwiseMatrix ) data
ID based indexing and slicing
Integration with diversity, ordination, and statistical tests
Read/write delimited text format
Common patterns:
Important notes:
DistanceMatrix enforces symmetry and a zero (hollow) diagonal; it is a subclass of SymmetricMatrix
PairwiseMatrix (renamed from DissimilarityMatrix , which is kept as a deprecated alias) allows general/asymmetric values
IDs enable integration with metadata and biological knowledge
Compatible with pandas, numpy, and scikit learn
9. Biological Tables
Work with feature tables (OTU/ASV tables) common in microbiome research.
Key capabilities:
BIOM 2.1 HDF5 I/O via Table (the biom format class registered with scikit bio)
Table dispatch system (0.7.0+): functions accept any table like input — BIOM Table , pandas/polars DataFrame, NumPy array, or AnnData — without explicit conversion
Data augmentation techniques ( phylomix , mixup , aitchison mixup , compos cutmix )
Sample/feature filtering and normalization
Metadata integration
Common patterns:
Important notes:
BIOM tables are standard in QIIME 2 workflows
Table like NumPy/DataFrame inputs use samples × features. A native BIOM Table.matrix data uses features (observations) × samples ; transpose only when manually extracting it for a samples by features API, and align both ID vectors. Passing the Table directly lets scikit bio's dispatch handle orientation. See [table conventions](https://scikit.bio/docs/latest/table.html).
Supports sparse and dense representations
Return types are function specific: diversity drivers return Series/DistanceMatrix. Only API