Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Python library for biology: sequence manipulation (DNA/RNA/protein), pairwise/multiple alignment, phylogenetic trees (NJ, UPGMA), diversity (Shannon, Faith PD, Bray-Curtis, UniFrac), ordination (PCoA, CCA, RDA), stats (PERMANOVA, ANOSIM, Mantel), file I/O (FASTA, FASTQ, Newick, BIOM). Use for microbiome, community ecology, or phylogenetics.
.claude/skills/jaechang-hits-scikit-bio/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-04 | ✗→✓ | ▲ Improved | 192% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 209% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 552% | 0% |
| case-12 | ✗→✓ | ▲ Improved | 159% | 0% |
| case-16 | ✗→✓ | ▲ Improved | 390% | 0% |
scikit-bio is a comprehensive Python library for biological data analysis, spanning sequence manipulation, alignment, phylogenetics, microbial ecology, and multivariate statistics. It provides specialized data structures (DNA, RNA, Protein, DistanceMatrix, TreeNode, TabularMSA) that integrate with the broader Python scientific stack.
bashpip install scikit-bio # Optional: pip install biom-format — HDF5 BIOM table support # Optional: pip install matplotlib seaborn — visualization
pythonimport skbio from skbio.diversity import alpha_diversity, beta_diversity from skbio.stats.distance import permanova from skbio.stats.ordination import pcoa import numpy as np # Sample OTU counts (samples × features) counts = np.array([[10, 20, 30], [15, 25, 5], [5, 10, 40], [20, 5, 15]]) sample_ids = ['S1', 'S2', 'S3', 'S4'] grouping = ['control', 'control', 'treatment', 'treatment'] # Alpha diversity shannon = alpha_diversity('shannon', counts, ids=sample_ids) print(f"Shannon diversity: {shannon.values}") # [1.09, 1.04, 0.94, 1.03] # Beta diversity → PCoA → PERMANOVA bc_dm = beta_diversity('braycurtis', counts, ids=sample_ids) pcoa_results = pcoa(bc_dm) results = permanova(bc_dm, grouping, permutations=999) print(f"PERMANOVA p-value: {results['p-value']}")
pythonfrom skbio import DNA, RNA, Protein # Create and manipulate sequences dna = DNA('ATCGATCGATCG', metadata={'id': 'gene1', 'description': 'test'}) rc = dna.reverse_complement() rna = dna.transcribe() protein = rna.translate() print(f"DNA: {dna}, RC: {rc}, Protein: {protein}") # Motif finding and k-mer analysis motif_positions = dna.find_with_regex('ATG.{3}') kmer_freqs = dna.kmer_frequencies(k=3) print(f"3-mer frequencies: {dict(list(kmer_freqs.items())[:3])}") # Sequence properties print(f"Has degenerates: {dna.has_degenerates()}") print(f"GC content: {dna.gc_content():.2f}") degapped = dna.degap() # Remove gap characters
python# Metadata: sequence-level, positional, interval dna = DNA('ATCGATCG', metadata={'id': 'seq1'}, positional_metadata={'quality': [30, 35, 40, 38, 32, 36, 34, 33]}) dna.interval_metadata.add([(0, 4)], metadata={'type': 'promoter'}) print(f"Quality scores: {list(dna.positional_metadata['quality'])}")
pythonfrom skbio import DNA from skbio.alignment import local_pairwise_align_ssw, TabularMSA # Pairwise local alignment (Smith-Waterman via SSW) seq1 = DNA('ACTCGATCGATCGATCGATCG') seq2 = DNA('ATCGATCGATCGATCGATCGA') alignment, score, start_end = local_pairwise_align_ssw(seq1, seq2) print(f"Score: {score}, Positions: {start_end}") # Multiple sequence alignment from file msa = TabularMSA.read('alignment.fasta', constructor=DNA) consensus = msa.consensus() conservation = msa.conservation() print(f"Consensus: {consensus[:20]}, Conservation: {conservation[:5]}")
pythonfrom skbio import TreeNode, DistanceMatrix from skbio.tree import nj, upgma # Build tree from distance matrix data = [[0, 5, 9, 9], [5, 0, 10, 10], [9, 10, 0, 8], [9, 10, 8, 0]] dm = DistanceMatrix(data, ids=['A', 'B', 'C', 'D']) tree = nj(dm) print(tree.ascii_art()) # Tree operations subtree = tree.shear(['A', 'B', 'C']) # Prune to subset tips = [node.name for node in tree.tips()] lca = tree.lowest_common_ancestor(['A', 'B']) print(f"Tips: {tips}, LCA children: {len(list(lca.children))}") # Tree comparison tree2 = upgma(dm) rf_dist = tree.compare_rfd(tree2) cophenetic_dm = tree.cophenetic_matrix() print(f"Robinson-Foulds distance: {rf_dist}")
pythonfrom skbio.diversity import alpha_diversity, beta_diversity import numpy as np counts = np.array([[10, 20, 30, 0], [15, 25, 5, 10], [5, 10, 40, 2]]) sample_ids = ['S1', 'S2', 'S3'] # Alpha diversity (multiple metrics) for metric in ['shannon', 'simpson', 'observed_otus', 'pielou_e']: alpha = alpha_diversity(metric, counts, ids=sample_ids) print(f"{metric}: {alpha.values.round(3)}") # Beta diversity bc_dm = beta_diversity('braycurtis', counts, ids=sample_ids) jaccard_dm = beta_diversity('jaccard', counts, ids=sample_ids) print(f"Bray-Curtis S1-S2: {bc_dm['S1', 'S2']:.3f}")
python# Phylogenetic diversity (requires tree + OTU IDs) from skbio.diversity import alpha_diversity, beta_diversity faith_pd = alpha_diversity('faith_pd', counts, ids=sample_ids, tree=tree, otu_ids=feature_ids) unifrac_dm = beta_diversity('unweighted_unifrac', counts, ids=sample_ids, tree=tree, otu_ids=feature_ids) w_unifrac_dm = beta_diversity('weighted_unifrac', counts, ids=sample_ids, tree=tree, otu_ids=feature_ids) print(f"Faith PD: {faith_pd.values}")
pythonfrom skbio.stats.ordination import pcoa, cca # PCoA from distance matrix pcoa_results = pcoa(bc_dm) pc1 = pcoa_results.samples['PC1'] pc2 = pcoa_results.samples['PC2'] prop = pcoa_results.proportion_explained print(f"PC1 explains {prop.iloc[0]:.1%}, PC2 explains {prop.iloc[1]:.1%}") # CCA with environmental variables (constrained ordination) # species_matrix: samples × species counts # env_matrix: samples × environmental variables cca_results = cca(species_matrix, env_matrix) biplot_scores = cca_results.biplot_scores print(f"Biplot scores shape: {biplot_scores.shape}") # Save/load ordination results pcoa_results.write('pcoa_results.txt') loaded = skbio.OrdinationResults.read('pcoa_results.txt')
pythonfrom skbio.stats.distance import permanova, anosim, permdisp, mantel grouping = ['control', 'control', 'treatment'] # PERMANOVA — test group differences perm_results = permanova(bc_dm, grouping, permutations=999) print(f"PERMANOVA: F={perm_results['test statistic']:.3f}, " f"p={perm_results['p-value']:.4f}") # ANOSIM — alternative group test anosim_results = anosim(bc_dm, grouping, permutations=999) print(f"ANOSIM: R={anosim_results['test statistic']:.3f}, " f"p={anosim_results['p-value']:.4f}") # PERMDISP — test homogeneity of dispersions permdisp_results = permdisp(bc_dm, grouping, permutations=999) # Mantel test — correlation between distance matrices r, p_value, n = mantel(bc_dm, jaccard_dm, method='pearson', permutations=999) print(f"Mantel: r={r:.3f}, p={p_value:.4f}")
pythonimport skbio # Read various formats seq = skbio.DNA.read('input.fasta', format='fasta') tree = skbio.TreeNode.read('tree.nwk') dm = skbio.DistanceMatrix.read('distances.txt') # Memory-efficient reading (generator for large files) for seq in skbio.io.read('large.fasta', format='fasta', constructor=skbio.DNA): print(f"{seq.metadata['id']}: {len(seq)} bp") # Write and convert formats seq.write('output.fasta', format='fasta') seqs = list(skbio.io.read('input.fastq', format='fastq', constructor=skbio.DNA)) skbio.io.write(seqs, format='fasta', into='output.fasta')
pythonfrom skbio import DistanceMatrix import numpy as np # Create from array data = np.array([[0, 1, 2], [1, 0, 3], [2, 3, 0]]) dm = DistanceMatrix(data, ids=['A', 'B', 'C']) # Access and slice print(f"A-B distance: {dm['A', 'B']}") subset = dm.filter(['A', 'C']) condensed = dm.condensed_form() # scipy-compatible df = dm.to_data_frame() print(f"Shape: {df.shape}")
| Metric Type | Non-Phylogenetic | Phylogenetic (requires tree) | |-------------|-----------------|------------------------------| | Alpha diversity | Shannon, Simpson, observed_otus, Pielou's evenness | Faith's PD | | Beta diversity | Bray-Curtis, Jaccard | Unweighted UniFrac, Weighted UniFrac |
Diversity functions require integer abundance counts, not relative frequencies. If you have proportions, multiply back:
python# Wrong: relative abundance # counts = np.array([0.1, 0.5, 0.4]) # Correct: integer counts counts = np.array([10, 50, 40])
pythonimport skbio from skbio import TreeNode from skbio.diversity import alpha_diversity, beta_diversity from skbio.stats.ordination import pcoa from skbio.stats.distance import permanova import numpy as np # 1. Load data counts = np.loadtxt('otu_table.tsv', delimiter='\t', dtype=int, skiprows=1) sample_ids = ['S1', 'S2', 'S3', 'S4', 'S5', 'S6'] feature_ids = ['OTU1', 'OTU2', 'OTU3', 'OTU4'] tree = TreeNode.read('phylogeny.nwk') grouping = ['control', 'control', 'control', 'treatment', 'treatment', 'treatment'] # 2. Alpha diversity shannon = alpha_diversity('shannon', counts, ids=sample_ids) faith = alpha_diversity('faith_pd', counts, ids=sample_ids, tree=tree, otu_ids=feature_ids) print(f"Mean Shannon - Control: {shannon[:3].mean():.2f}, " f"Treatment: {shannon[3:].mean():.2f}") # 3. Beta diversity + PCoA unifrac_dm = beta_diversity('unweighted_unifrac', counts, ids=sample_ids, tree=tree, otu_ids=feature_ids) pcoa_results = pcoa(unifrac_dm) print(f"PC1: {pcoa_results.proportion_explained.iloc[0]:.1%} variance") # 4. Statistical testing results = permanova(unifrac_dm, grouping, permutations=999) print(f"PERMANOVA p={results['p-value']:.4f}")
pythonfrom skbio import DNA, DistanceMatrix from skbio.tree import nj from skbio.alignment import local_pairwise_align_ssw import numpy as np # 1. Read sequences seqs = list(skbio.io.read('sequences.fasta', format='fasta', constructor=DNA)) n = len(seqs) print(f"Loaded {n} sequences") # 2. Compute pairwise distances (Hamming-like via alignment scores) dist_data = np.zeros((n, n)) for i in range(n): for j in range(i+1, n): _, score, _ = local_pairwise_align_ssw(seqs[i], seqs[j]) max_len = max(len(seqs[i]), len(seqs[j])) dist_data[i, j] = dist_data[j, i] = 1 - (score / max_len) # 3. Build tree ids = [s.metadata.get('id', f'seq{i}') for i, s in enumerate(seqs)] dm = DistanceMatrix(dist_data, ids=ids) tree = nj(dm) print(tree.ascii_art()) # 4. Analyze tree tree.write('output.nwk', format='newick') cophenetic = tree.cophenetic_matrix() print(f"Cophenetic matrix shape: {cophenetic.shape}")
skbio.io.read with constructor=DNA)positional_metadata['quality']find_with_regex() and sequence slicingfind_with_regex('ATG.{3}')dna.transcribe().translate()skbio.io.write()| Parameter | Function | Default | Effect | |-----------|----------|---------|--------| | metric | alpha/beta_diversity | Required | Diversity metric name (e.g., 'shannon', 'braycurtis') | | permutations | permanova/anosim/mantel | 999 | Number of permutations; higher = more precise p-values | | tree | alpha/beta_diversity | None | Required for phylogenetic metrics (Faith PD, UniFrac) | | otu_ids | alpha/beta_diversity | None | Feature IDs mapping counts to tree tips | | method | mantel | 'pearson' | Correlation method: 'pearson' or 'spearman' | | constructor | io.read | None | Sequence class for parsing (DNA, RNA, Protein) | | format | io.read/write | Auto | File format (fasta, fastq, newick, etc.) | | genetic_code | translate | 1 | NCBI genetic code (1=standard, 11=bacterial) | | k | kmer_frequencies | Required | k-mer length for frequency calculation |
skbio.io.read() returns a generator; avoid list() on millions of sequencestree and otu_ids; prune tree to feature set with tree.shear(feature_ids)pythonfrom skbio.diversity import subsample_counts, alpha_diversity import numpy as np # Rarefy to minimum depth min_depth = min(counts.sum(axis=1)) rarefied = np.array([subsample_counts(row, n=min_depth) for row in counts]) print(f"Rarefied to {min_depth} counts per sample") # Calculate diversity on rarefied data shannon = alpha_diversity('shannon', rarefied, ids=sample_ids)
pythonfrom skbio.diversity import partial_beta_diversity import itertools # Only compute specific pairs (saves time on large matrices) pairs = list(itertools.combinations(sample_ids[:10], 2)) partial_dm = partial_beta_diversity('braycurtis', counts, ids=sample_ids, id_pairs=pairs) print(f"Computed {len(pairs)} pairwise distances")
pythonfrom skbio import Table import numpy as np # Read BIOM table table = Table.read('feature_table.biom') print(f"Samples: {table.shape[1]}, Features: {table.shape[0]}") # Filter low-abundance features filtered = table.filter(lambda row, id_, md: row.sum() > 10, axis='observation') # Convert to pandas df = table.to_dataframe() # Normalize to relative abundance rel_abundance = df.div(df.sum(axis=0), axis=1)
| Problem | Cause | Solution | |---------|-------|----------| | ValueError: Ids must be unique | Duplicate IDs in DistanceMatrix/sequences | Deduplicate IDs: ids = list(dict.fromkeys(ids)) | | ValueError: Counts must be integers | Relative abundance passed to diversity | Use integer counts; multiply back: (proportions * 1000).astype(int) | | Memory error on large FASTA | Loading all sequences at once | Use generator: for seq in skbio.io.read(...) | | Tree tip / OTU ID mismatch | Phylogenetic diversity fails | Prune tree: tree = tree.shear(feature_ids) | | PERMANOVA p=0.001 but groups overlap in PCoA | Significant dispersion difference | Run permdisp() to check; PERMANOVA tests location AND dispersion | | Wrong translation | Default genetic code (standard) used for bacteria | Set genetic_code=11 for bacterial/archaeal sequences | | Slow NJ tree construction | O(n³) for large n | Use GME or BME for >1000 taxa: from skbio.tree import gme |
references/extended_api.md — Extended API reference covering advanced alignment parameters (SSW, gap penalties, CIGAR), tree construction algorithms (NJ vs UPGMA vs GME/BME), BIOM table manipulation, protein embeddings, and integration patterns with QIIME 2, pandas, and scikit-learnNot migrated from original: the original's single api_reference.md (749 lines) was condensed into references/extended_api.md with focus on capabilities not covered inline. Omitted content: basic examples duplicating Core API, verbose troubleshooting (covered in Troubleshooting table above).
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | pass→pass | 14,271 | 22,811 | +60% | 1 | 1 | 0% | 2,368 | 6,682 | +182% | 0 | 0 | — |
case-02 | pass→pass | 13,866 | 12,971 | -6% | 1 | 1 | 0% | 2,446 | 7,301 | +198% | 0 | 0 | — |
case-03 | pass→pass | 11,350 | 6,856 | -40% | 1 | 1 | 0% | 1,807 | 6,380 | +253% | 0 | 0 | — |
case-04 | fail→pass | 12,124 | 7,752 | -36% | 1 | 1 | 0% | 2,299 | 6,713 | +192% | 0 | 0 | — |
case-05 | fail→pass | 14,440 | 13,487 | -7% | 1 | 1 | 0% | 2,415 | 7,459 | +209% | 0 | 0 | — |
case-06 | pass→pass | 11,148 | 7,759 | -30% | 1 | 1 | 0% | 1,860 | 6,576 | +254% | 0 | 0 | — |
case-07 | pass→pass | 11,414 | 5,569 | -51% | 1 | 1 | 0% | 1,882 | 6,181 | +228% | 0 | 0 | — |
case-08 | pass→pass | 15,894 | 9,583 | -40% | 1 | 1 | 0% | 2,709 | 6,867 | +153% | 0 | 0 | — |
case-09 | pass→pass | 11,974 | 7,487 | -37% | 1 | 1 | 0% | 2,195 | 6,568 | +199% | 0 | 0 | — |
case-10 | fail→pass | 5,518 | 5,667 | +3% | 1 | 1 | 0% | 952 | 6,206 | +552% | 0 | 0 | — |
case-11 | fail→fail | 13,403 | 3,878 | -71% | 1 | 1 | 0% | 2,291 | 5,952 | +160% | 0 | 0 | — |
case-12 | fail→pass | 12,620 | 4,618 | -63% | 1 | 1 | 0% | 2,368 | 6,132 | +159% | 0 | 0 | — |
case-13 | pass→pass | 7,264 | 3,896 | -46% | 1 | 1 | 0% | 1,417 | 5,899 | +316% | 0 | 0 | — |
case-14 | pass→pass | 8,942 | 4,580 | -49% | 1 | 1 | 0% | 1,546 | 5,997 | +288% | 0 | 0 | — |
case-15 | pass→pass | 11,123 | 4,875 | -56% | 1 | 1 | 0% | 1,631 | 6,212 | +281% | 0 | 0 | — |
case-16 | fail→pass | 6,771 | 3,531 | -48% | 1 | 1 | 0% | 1,188 | 5,823 | +390% | 0 | 0 | — |
case-17 | pass→pass | 12,700 | 8,883 | -30% | 1 | 1 | 0% | 2,128 | 6,794 | +219% | 0 | 0 | — |
case-18 | pass→pass | 5,897 | 3,825 | -35% | 1 | 1 | 0% | 1,052 | 5,961 | +467% | 0 | 0 | — |
case-19 | fail→pass | 8,550 | 5,623 | -34% | 1 | 1 | 0% | 1,610 | 6,207 | +286% | 0 | 0 | — |
case-20 | pass→pass | 5,037 | 6,232 | +24% | 1 | 1 | 0% | 927 | 6,357 | +586% | 0 | 0 | — |
case-21 | fail→fail | 9,900 | 3,385 | -66% | 1 | 1 | 0% | 1,761 | 5,865 | +233% | 0 | 0 | — |
case-22 | pass→pass | 6,559 | 2,980 | -55% | 1 | 1 | 0% | 1,161 | 5,674 | +389% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +27 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.