Bio.SearchIO.BlatIO module

Bio.SearchIO parser for BLAT output formats.

This module adds support for parsing BLAT outputs. BLAT (BLAST-Like Alignment Tool) is a sequence similarity search program initially built for annotating the human genome.

Bio.SearchIO.BlastIO was tested using standalone BLAT version 34, psLayout version 3. It should be able to parse psLayout version 4 without problems.

More information on BLAT is available from these sites:

Supported Formats

BlatIO supports parsing, indexing, and writing for both PSL and PSLX output formats, with or without header. To parse, index, or write PSLX files, use the ‘pslx’ keyword argument and set it to True.

# blat-psl defaults to PSL files >>> from Bio import SearchIO >>> psl = ‘Blat/psl_34_004.psl’ >>> qresult =, ‘blat-psl’) >>> qresult QueryResult(id=’hg19_dna’, 10 hits)

# set the pslx flag to parse PSLX files >>> pslx = ‘Blat/pslx_34_004.pslx’ >>> qresult =, ‘blat-psl’, pslx=True) >>> qresult QueryResult(id=’hg19_dna’, 10 hits)

For parsing and indexing, you do not need to specify whether the file has a header or not. For writing, if you want to write a header, you can set the ‘header’ keyword argument to True. This will write a ‘psLayout version 3’ header to your output file.

from Bio import SearchIO qresult =, ‘blat-psl’) SearchIO.write(qresult, ‘header.psl’, header=True) <stdout> (1, 10, 19, 23)

Note that the number of HSPFragments written may exceed the number of HSP objects. This is because in PSL files, it is possible to have single matches consisting of noncontiguous sequence fragments. This is where the HSPFragment object comes into play. These fragments are grouped into a single HSP because they share the same statistics (e.g. match numbers, BLAT score, etc.). However, they do not share the same sequence attributes, such as the start and end coordinates, making them distinct objects.

In addition to parsing PSL(X) files, BlatIO also computes the percent identities and scores of your search results. This is done using the calculation formula posted here: It mimics the score and percent identity calculation done by UCSC’s web BLAT service.

Since BlatIO parses the file in a single pass, it expects all results from the same query to be in consecutive rows. If the results from one query are spread in nonconsecutive rows, BlatIO will consider them to be separate QueryResult objects.

In most cases, the PSL(X) format uses the same coordinate system as Python (zero-based, half open). These coordinates are anchored on the plus strand. However, if the query aligns on the minus strand, BLAT will anchor the qStarts coordinates on the minus strand instead. BlatIO is aware of this, and will re-anchor the qStarts coordinates to the plus strand whenever it sees a minus strand query match. Conversely, when you write out to a PSL(X) file, BlatIO will reanchor qStarts to the minus strand again.

BlatIO provides the following attribute-column mapping:



Column Name, Value



Q name, query sequence ID


Q size, query sequence full length



T name, hit sequence ID


T size, hit sequence full length



T end, end coordinate of the last hit fragment


T gap bases, number of bases inserted in hit


T gap count, number of hit gap inserts


blockSizes, sizes of each fragment


T start, start coordinate of the first hit fragment


tStarts, start coordinate of each hit fragment


match, number of non-repeat matches


mismatch, number of mismatches


rep. match, number of matches that are part of repeats


N’s, number of N bases


Q end, end coordinate of the last


query fragment Q gap bases, number of bases inserted in query


Q gap count, number of query gap inserts


blockSizes, sizes of each fragment


Q start, start coordinate of the first query block


qStarts, start coordinate of each query fragment

len *

block count, the number of blocks in the alignment



hit sequence, if present


strand, hit sequence strand


query sequence, if present


strand, query sequence strand

In addition to the column mappings above, BlatIO also provides the following object attributes:






Q gap count + T gap count, total

number of gap openings


matches + repmatches, total number of identical residues


percent identity, calculated using UCSC’s formula


boolean, whether the query sequence is a protein


HSP score, calculated using UCSC’s formula

Finally, the default HSP and HSPFragment properties are also provided. See the HSP and HSPFragment documentation for more details on these properties.


You can obtain the number of blocks / fragments in the HSP by invoking len on the HSP

class Bio.SearchIO.BlatIO.BlatPslParser(handle, pslx=False)

Bases: object

Parser for the BLAT PSL format.

__init__(self, handle, pslx=False)

Initialize the class.


Iterate over BlatPslParser, yields query results.

class Bio.SearchIO.BlatIO.BlatPslIndexer(filename, pslx=False)

Bases: Bio.SearchIO._index.SearchIndexer

Indexer class for BLAT PSL output.

__init__(self, filename, pslx=False)

Initialize the class.


Iterate over the file handle; yields key, start offset, and length.

get_raw(self, offset)

Return raw bytes string of a QueryResult object from the given offset.

__abstractmethods__ = frozenset({})
class Bio.SearchIO.BlatIO.BlatPslWriter(handle, header=False, pslx=False)

Bases: object

Writer for the blat-psl format.

__init__(self, handle, header=False, pslx=False)

Initialize the class.

write_file(self, qresults)

Write query results to file.