Skillversitas

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

  1. The query is broken into short words (k-mers); hits in the database that share words become "seeds".
  2. Seeds are extended in both directions to full local alignments.
  3. Extensions are scored; only alignments above a threshold are reported, with E-values indicating statistical significance.
  4. Reading Results

    FieldMeaning
    Scorealignment quality; higher is better
    E valueexpected number of hits by chance; smaller is more significant (<1e-3 is a common filter)
    Identitypercent of aligned positions that match
    Query coveragefraction 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

    • 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.

    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.