$npx -y skills add LeonChaoX/qinyan-academic-skills --skill biopythonComprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for
| 1 | # Biopython: Computational Molecular Biology in Python |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Biopython is a comprehensive set of freely available Python tools for biological computation. It provides functionality for sequence manipulation, file I/O, database access, structural bioinformatics, phylogenetics, and many other bioinformatics tasks. The current version is **Biopython 1.85** (released January 2025), which supports Python 3 and requires NumPy. |
| 6 | |
| 7 | ## When to Use This Skill |
| 8 | |
| 9 | Use this skill when: |
| 10 | |
| 11 | - Working with biological sequences (DNA, RNA, or protein) |
| 12 | - Reading, writing, or converting biological file formats (FASTA, GenBank, FASTQ, PDB, mmCIF, etc.) |
| 13 | - Accessing NCBI databases (GenBank, PubMed, Protein, Gene, etc.) via Entrez |
| 14 | - Running BLAST searches or parsing BLAST results |
| 15 | - Performing sequence alignments (pairwise or multiple sequence alignments) |
| 16 | - Analyzing protein structures from PDB files |
| 17 | - Creating, manipulating, or visualizing phylogenetic trees |
| 18 | - Finding sequence motifs or analyzing motif patterns |
| 19 | - Calculating sequence statistics (GC content, molecular weight, melting temperature, etc.) |
| 20 | - Performing structural bioinformatics tasks |
| 21 | - Working with population genetics data |
| 22 | - Any other computational molecular biology task |
| 23 | |
| 24 | ## Core Capabilities |
| 25 | |
| 26 | Biopython is organized into modular sub-packages, each addressing specific bioinformatics domains: |
| 27 | |
| 28 | 1. **Sequence Handling** - Bio.Seq and Bio.SeqIO for sequence manipulation and file I/O |
| 29 | 2. **Alignment Analysis** - Bio.Align and Bio.AlignIO for pairwise and multiple sequence alignments |
| 30 | 3. **Database Access** - Bio.Entrez for programmatic access to NCBI databases |
| 31 | 4. **BLAST Operations** - Bio.Blast for running and parsing BLAST searches |
| 32 | 5. **Structural Bioinformatics** - Bio.PDB for working with 3D protein structures |
| 33 | 6. **Phylogenetics** - Bio.Phylo for phylogenetic tree manipulation and visualization |
| 34 | 7. **Advanced Features** - Motifs, population genetics, sequence utilities, and more |
| 35 | |
| 36 | ## Installation and Setup |
| 37 | |
| 38 | Install Biopython using pip (requires Python 3 and NumPy): |
| 39 | |
| 40 | ```python |
| 41 | uv pip install biopython |
| 42 | ``` |
| 43 | |
| 44 | For NCBI database access, always set your email address (required by NCBI): |
| 45 | |
| 46 | ```python |
| 47 | from Bio import Entrez |
| 48 | Entrez.email = "your.email@example.com" |
| 49 | |
| 50 | # Optional: API key for higher rate limits (10 req/s instead of 3 req/s) |
| 51 | Entrez.api_key = "your_api_key_here" |
| 52 | ``` |
| 53 | |
| 54 | ## Using This Skill |
| 55 | |
| 56 | This skill provides comprehensive documentation organized by functionality area. When working on a task, consult the relevant reference documentation: |
| 57 | |
| 58 | ### 1. Sequence Handling (Bio.Seq & Bio.SeqIO) |
| 59 | |
| 60 | **Reference:** `references/sequence_io.md` |
| 61 | |
| 62 | Use for: |
| 63 | - Creating and manipulating biological sequences |
| 64 | - Reading and writing sequence files (FASTA, GenBank, FASTQ, etc.) |
| 65 | - Converting between file formats |
| 66 | - Extracting sequences from large files |
| 67 | - Sequence translation, transcription, and reverse complement |
| 68 | - Working with SeqRecord objects |
| 69 | |
| 70 | **Quick example:** |
| 71 | ```python |
| 72 | from Bio import SeqIO |
| 73 | |
| 74 | # Read sequences from FASTA file |
| 75 | for record in SeqIO.parse("sequences.fasta", "fasta"): |
| 76 | print(f"{record.id}: {len(record.seq)} bp") |
| 77 | |
| 78 | # Convert GenBank to FASTA |
| 79 | SeqIO.convert("input.gb", "genbank", "output.fasta", "fasta") |
| 80 | ``` |
| 81 | |
| 82 | ### 2. Alignment Analysis (Bio.Align & Bio.AlignIO) |
| 83 | |
| 84 | **Reference:** `references/alignment.md` |
| 85 | |
| 86 | Use for: |
| 87 | - Pairwise sequence alignment (global and local) |
| 88 | - Reading and writing multiple sequence alignments |
| 89 | - Using substitution matrices (BLOSUM, PAM) |
| 90 | - Calculating alignment statistics |
| 91 | - Customizing alignment parameters |
| 92 | |
| 93 | **Quick example:** |
| 94 | ```python |
| 95 | from Bio import Align |
| 96 | |
| 97 | # Pairwise alignment |
| 98 | aligner = Align.PairwiseAligner() |
| 99 | aligner.mode = 'global' |
| 100 | alignments = aligner.align("ACCGGT", "ACGGT") |
| 101 | print(alignments[0]) |
| 102 | ``` |
| 103 | |
| 104 | ### 3. Database Access (Bio.Entrez) |
| 105 | |
| 106 | **Reference:** `references/databases.md` |
| 107 | |
| 108 | Use for: |
| 109 | - Searching NCBI databases (PubMed, GenBank, Protein, Gene, etc.) |
| 110 | - Downloading sequences and records |
| 111 | - Fetching publication information |
| 112 | - Finding related records across databases |
| 113 | - Batch downloading with proper rate limiting |
| 114 | |
| 115 | **Quick example:** |
| 116 | ```python |
| 117 | from Bio import Entrez |
| 118 | Entrez.email = "your.email@example.com" |
| 119 | |
| 120 | # Search PubMed |
| 121 | handle = Entrez.esearch(db="pubmed", term="biopython", retmax=10) |
| 122 | results = Entrez.read(handle) |
| 123 | handle.close() |
| 124 | print(f"Found {results['Count']} results") |
| 125 | ``` |
| 126 | |
| 127 | ### 4. BLAST Operations (Bio.Blast) |
| 128 | |
| 129 | **Reference:** `references/blast.md` |
| 130 | |
| 131 | Use for: |
| 132 | - Running BLAST searches via NCBI web services |
| 133 | - Running local BLAST searches |
| 134 | - Parsing BLAST XML output |
| 135 | - Filtering results by E-value or identity |
| 136 | - Extracting hit sequences |
| 137 | |
| 138 | **Quick example:** |
| 139 | ```python |
| 140 | f |