1---
2name: biology-biopython
3description: Bioinformatics with Biopython for sequence manipulation, file parsing, BLAST, and phylogenetics. Use when working with DNA/RNA/protein sequences or biological databases.
4metadata:
5 source: https://skillmd.com/skills/enuno/biology-biopython
6 category: domain
7 trigger-keywords: "sequence,FASTA,genome,protein,BLAST,phylogenetic,biopython,bioinformatics,gene,DNA,RNA"
8 applicable-stages: "9,10,12"
9 priority: "4"
10 version: "1.0"
11 author: researchclaw
12 references: "adapted from K-Dense-AI/claude-scientific-skills"
13---
14
15## Biopython Bioinformatics Best Practice
16
17### Sequence Manipulation
181. Create sequences: `from Bio.Seq import Seq; seq = Seq("ATGCGA")`
192. Complement: `seq.complement()`; Reverse complement: `seq.reverse_complement()`
203. Transcription: `seq.transcribe()` (DNA to RNA)
214. Translation: `seq.translate()` (DNA/RNA to protein)
225. GC content: `from Bio.SeqUtils import gc_fraction; gc_fraction(seq)`
236. Molecular weight: `from Bio.SeqUtils import molecular_weight`
24
25### File Parsing (SeqIO)
261. Read FASTA: `for rec in SeqIO.parse("file.fasta", "fasta"): ...`
272. Read GenBank: `for rec in SeqIO.parse("file.gb", "genbank"): ...`
283. Read single record: `rec = SeqIO.read("file.fasta", "fasta")`
294. Write sequences: `SeqIO.write(records, "output.fasta", "fasta")`
305. Convert formats: `SeqIO.convert("input.gb", "genbank", "output.fasta", "fasta")`
316. Index large files: `idx = SeqIO.index("large.fasta", "fasta")` for random access
32
33### BLAST Operations
341. Online BLAST: `from Bio.Blast import NCBIWWW; result = NCBIWWW.qblast("blastn", "nt", seq)`
352. Parse results: `from Bio.Blast import NCBIXML; records = NCBIXML.parse(result)`
363. Local BLAST: run via subprocess, parse XML output with NCBIXML
374. Always set `Entrez.email` before any NCBI access
385. Filter results by e-value (typically < 1e-5) and coverage
39
40### NCBI Database Access (Entrez)
411. Always set email: `Entrez.email = "your@email.com"`
422. Search: `handle = Entrez.esearch(db="pubmed", term="query")`
433. Fetch records: `handle = Entrez.efetch(db="nucleotide", id="ID", rettype="fasta")`
444. Use API key for higher rate limits (10 req/s vs 3 req/s)
455. Respect NCBI rate limits; add delays between batch requests
46
47### Phylogenetics (Bio.Phylo)
481. Read trees: `from Bio import Phylo; tree = Phylo.read("tree.nwk", "newick")`
492. Draw trees: `Phylo.draw(tree)` or `Phylo.draw_ascii(tree)`
503. Supported formats: newick, nexus, phyloxml
514. Traverse clades: `for clade in tree.find_clades(): ...`
525. Calculate distances: `tree.distance(clade1, clade2)`
53
54### Structure Analysis (Bio.PDB)
551. Parse PDB: `parser = PDBParser(); structure = parser.get_structure("id", "file.pdb")`
562. Hierarchy: Structure > Model > Chain > Residue > Atom
573. Get atoms: iterate through `structure.get_atoms()`
584. Calculate distances: use atom coordinate vectors
595. For mmCIF files: use `MMCIFParser()` instead of `PDBParser()`
60
61### Common Pitfalls
621. Always handle `SeqIO.parse` as an iterator — it exhausts after one pass
632. Check sequence alphabet compatibility before operations
643. Large files: use `SeqIO.index()` not `SeqIO.to_dict()` to avoid memory issues
654. Set proper timeout for remote BLAST queries (can take minutes)
665. Validate parsed data — missing annotations are common in public databases