$npx -y skills add LeonChaoX/qinyan-academic-skills --skill scikit-bioBiological data toolkit. Sequence analysis, alignments, phylogenetic trees, diversity metrics (alpha/beta, UniFrac), ordination (PCoA), PERMANOVA, FASTA/Newick I/O, for microbiome analysis.
| 1 | # scikit-bio |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | scikit-bio is a comprehensive Python library for working with biological data. Apply this skill for bioinformatics analyses spanning sequence manipulation, alignment, phylogenetics, microbial ecology, and multivariate statistics. |
| 6 | |
| 7 | ## When to Use This Skill |
| 8 | |
| 9 | This skill should be used when the user: |
| 10 | - Works with biological sequences (DNA, RNA, protein) |
| 11 | - Needs to read/write biological file formats (FASTA, FASTQ, GenBank, Newick, BIOM, etc.) |
| 12 | - Performs sequence alignments or searches for motifs |
| 13 | - Constructs or analyzes phylogenetic trees |
| 14 | - Calculates diversity metrics (alpha/beta diversity, UniFrac distances) |
| 15 | - Performs ordination analysis (PCoA, CCA, RDA) |
| 16 | - Runs statistical tests on biological/ecological data (PERMANOVA, ANOSIM, Mantel) |
| 17 | - Analyzes microbiome or community ecology data |
| 18 | - Works with protein embeddings from language models |
| 19 | - Needs to manipulate biological data tables |
| 20 | |
| 21 | ## Core Capabilities |
| 22 | |
| 23 | ### 1. Sequence Manipulation |
| 24 | |
| 25 | Work with biological sequences using specialized classes for DNA, RNA, and protein data. |
| 26 | |
| 27 | **Key operations:** |
| 28 | - Read/write sequences from FASTA, FASTQ, GenBank, EMBL formats |
| 29 | - Sequence slicing, concatenation, and searching |
| 30 | - Reverse complement, transcription (DNA→RNA), and translation (RNA→protein) |
| 31 | - Find motifs and patterns using regex |
| 32 | - Calculate distances (Hamming, k-mer based) |
| 33 | - Handle sequence quality scores and metadata |
| 34 | |
| 35 | **Common patterns:** |
| 36 | ```python |
| 37 | import skbio |
| 38 | |
| 39 | # Read sequences from file |
| 40 | seq = skbio.DNA.read('input.fasta') |
| 41 | |
| 42 | # Sequence operations |
| 43 | rc = seq.reverse_complement() |
| 44 | rna = seq.transcribe() |
| 45 | protein = rna.translate() |
| 46 | |
| 47 | # Find motifs |
| 48 | motif_positions = seq.find_with_regex('ATG[ACGT]{3}') |
| 49 | |
| 50 | # Check for properties |
| 51 | has_degens = seq.has_degenerates() |
| 52 | seq_no_gaps = seq.degap() |
| 53 | ``` |
| 54 | |
| 55 | **Important notes:** |
| 56 | - Use `DNA`, `RNA`, `Protein` classes for grammared sequences with validation |
| 57 | - Use `Sequence` class for generic sequences without alphabet restrictions |
| 58 | - Quality scores automatically loaded from FASTQ files into positional metadata |
| 59 | - Metadata types: sequence-level (ID, description), positional (per-base), interval (regions/features) |
| 60 | |
| 61 | ### 2. Sequence Alignment |
| 62 | |
| 63 | Perform pairwise and multiple sequence alignments using dynamic programming algorithms. |
| 64 | |
| 65 | **Key capabilities:** |
| 66 | - Global alignment (Needleman-Wunsch with semi-global variant) |
| 67 | - Local alignment (Smith-Waterman) |
| 68 | - Configurable scoring schemes (match/mismatch, gap penalties, substitution matrices) |
| 69 | - CIGAR string conversion |
| 70 | - Multiple sequence alignment storage and manipulation with `TabularMSA` |
| 71 | |
| 72 | **Common patterns:** |
| 73 | ```python |
| 74 | from skbio.alignment import local_pairwise_align_ssw, TabularMSA |
| 75 | |
| 76 | # Pairwise alignment |
| 77 | alignment = local_pairwise_align_ssw(seq1, seq2) |
| 78 | |
| 79 | # Access aligned sequences |
| 80 | msa = alignment.aligned_sequences |
| 81 | |
| 82 | # Read multiple alignment from file |
| 83 | msa = TabularMSA.read('alignment.fasta', constructor=skbio.DNA) |
| 84 | |
| 85 | # Calculate consensus |
| 86 | consensus = msa.consensus() |
| 87 | ``` |
| 88 | |
| 89 | **Important notes:** |
| 90 | - Use `local_pairwise_align_ssw` for local alignments (faster, SSW-based) |
| 91 | - Use `StripedSmithWaterman` for protein alignments |
| 92 | - Affine gap penalties recommended for biological sequences |
| 93 | - Can convert between scikit-bio, BioPython, and Biotite alignment formats |
| 94 | |
| 95 | ### 3. Phylogenetic Trees |
| 96 | |
| 97 | Construct, manipulate, and analyze phylogenetic trees representing evolutionary relationships. |
| 98 | |
| 99 | **Key capabilities:** |
| 100 | - Tree construction from distance matrices (UPGMA, WPGMA, Neighbor Joining, GME, BME) |
| 101 | - Tree manipulation (pruning, rerooting, traversal) |
| 102 | - Distance calculations (patristic, cophenetic, Robinson-Foulds) |
| 103 | - ASCII visualization |
| 104 | - Newick format I/O |
| 105 | |
| 106 | **Common patterns:** |
| 107 | ```python |
| 108 | from skbio import TreeNode |
| 109 | from skbio.tree import nj |
| 110 | |
| 111 | # Read tree from file |
| 112 | tree = TreeNode.read('tree.nwk') |
| 113 | |
| 114 | # Construct tree from distance matrix |
| 115 | tree = nj(distance_matrix) |
| 116 | |
| 117 | # Tree operations |
| 118 | subtree = tree.shear(['taxon1', 'taxon2', 'taxon3']) |
| 119 | tips = [node for node in tree.tips()] |
| 120 | lca = tree.lowest_common_ancestor(['taxon1', 'taxon2']) |
| 121 | |
| 122 | # Calculate distances |
| 123 | patristic_dist = tree.find('taxon1').distance(tree.find('taxon2')) |
| 124 | cophenetic_matrix = tree.cophenetic_matrix() |
| 125 | |
| 126 | # Compare trees |
| 127 | rf_distance = tree.robinson_foulds(other_tree) |
| 128 | ``` |
| 129 | |
| 130 | **Important notes:** |
| 131 | - Use `nj()` for neighbor joining (classic phylogenetic method) |
| 132 | - Use `upgma()` for UPGMA (assumes molecular clock) |
| 133 | - GME and BME are highly scalable for large trees |
| 134 | - Trees can be rooted or unrooted; some metrics require specific rooting |
| 135 | |
| 136 | ### 4. Diversity Analysis |
| 137 | |
| 138 | Calculate alpha and beta diversity metrics for microbial ecology and community analysis. |
| 139 | |
| 140 | **Key capabilities:** |
| 141 | - Alpha diversity: richness, Shannon entropy, Simpson index, Faith's PD, Pielou's evenness |
| 142 | - Beta diversity: Bray |