Overview of BLAST
BLAST (Basic Local Alignment Search Tool) is NCBI's fast algorithm for finding similar sequences in a database. It heuristically finds high-scoring local alignments, making it practical to search billions of sequences in seconds. In Biopython you run BLAST through NCBI's web services or parse result files with Bio.Blast.NCBIXML.
How BLAST Works
- The query is broken into short words (k-mers); hits in the database that share words become "seeds".
- Seeds are extended in both directions to full local alignments.
- Extensions are scored; only alignments above a threshold are reported, with E-values indicating statistical significance.
- blastn - nucleotide vs nucleotide.
- blastp - protein vs protein.
- blastx - translate query nucleotide, search protein DB.
- tblastn - query protein against translated nucleotide DB.
- tblastx - both translated; slow, for distant relationships.
Reading Results
| Field | Meaning |
|---|---|
| Score | alignment quality; higher is better |
| E value | expected number of hits by chance; smaller is more significant (<1e-3 is a common filter) |
| Identity | percent of aligned positions that match |
| Query coverage | fraction of the query covered by the hit |
Running BLAST (Web or API)
# command line if you have the BLAST+ binaries
blastn -query seq.fa -db nt -out result.xml -outfmt 5
# or via NCBI's Python-friendly Entrez + eutils for BLAST REST
# (submit job, poll, fetch XML) - see the Entrez chapter for the pattern
Parsing Results with NCBIXML
from Bio.Blast import NCBIXML
for record in NCBIXML.parse("result.xml"):
print("query:", record.query, "len", record.query_length)
for hit in record.hits:
print(" hit:", hit.name, hit.accessionversion, "E", hit.expect)
for hsp in hit.hsps:
print(" score", hsp.score, "ident", hsp.identities,
"/ length", hsp.align_length)
if hsp.identities / hsp.align_length > 0.9 and hsp.expect < 1e-3:
print(" strong match")
Choosing the BLAST Program
Summary
BLAST finds statistically significant local sequence matches in large databases; read results by E-value (smaller = more significant), score, and identity. Run blastn/blastp and friends for the right query/target types, output in XML (outfmt 5), and parse with Bio.Blast.NCBIXML to iterate hits and HSPs programmatically.