Quick Guide and Next Steps
This chapter is the fast reference for everything covered, plus a roadmap for where to go next: which module for which job, the most common one-liners, and the order to learn the remaining pieces.
Module Map
| Need | Module | Key calls |
|---|---|---|
| Read/write sequences | Bio.SeqIO | parse, read, write, convert |
| Sequence operations | Bio.Seq | transcribe, translate, reverse_complement |
| Annotations | Bio.SeqFeature | features, location, qualifiers |
| Pairwise alignment | Bio.Align | PairwiseAligner |
| Multiple alignment | Bio.AlignIO | read, write, columns |
| BLAST results | Bio.Blast.NCBIXML | parse hits/hsps |
| NCBI queries | Bio.Entrez | esearch, efetch, esummary |
| SQL sequence store | Bio.BioSQL | DBUtils.connect, add_sequence |
| Motifs | Bio.motifs | create, parse, score |
| Clustering | Bio.Cluster | distance, cluster |
| Structures | Bio.PDB | PDBParser, Superimposer |
| Trees | Bio.Phylo | read, draw |
| Population stats | Bio.PopGen | allele frequencies, pi, Tajima's D |
Common One-Liners
from Bio import SeqIO
from Bio.Seq import Seq
# count records and total length
recs = list(SeqIO.parse("data.fasta", "fasta"))
print(len(recs), sum(len(r) for r in recs))
# reverse complement
str(Seq("ATGC").reverse_complement())
# translate a CDS
str(Seq("ATGAAATAA").translate())
# extract CDS translations from GenBank
for f in SeqIO.read("gene.gb", "genbank").features:
if f.type == "CDS":
print(f.qualifiers.get("translation", [""])[0][:30])
A Learning Path
- Sequences and I/O (Seq, SeqIO, SeqFeature) - the foundation; do a dozen small parsing exercises.
- Alignment (PairwiseAligner, AlignIO) - compare real sequences, read scores and identity.
- Databases (Entrez) - automate esearch/efetch with caching; build a small downloader.
- One deep module - PDB, Phylo, or PopGen - depending on your field, with a real dataset.
- Integration - a CLI app that chains several modules (this chapter's seqstats as the template).
Pitfalls to Avoid
- Forgetting the format argument to SeqIO - always pass it explicitly.
- Confusing Bio (import name) with biopython (package name).
- Reading qualifiers without defaults - GenBank qualifiers are lists; use .get(key, [])[0] safely.
- Leaking memory with list(SeqIO.parse(huge_file)) when a generator would do.
- Hitting NCBI without an API key or without caching - rate limits and politeness.
Summary
Use the module map to find the right tool (SeqIO for I/O, PairwiseAligner for alignment, Entrez for NCBI, PDB for structures), keep the one-liners as a cheatsheet, follow the staged learning path from sequences to a chained CLI app, and avoid the classic pitfalls - explicit formats, safe qualifier access, generators over lists, and polite Entrez usage.