# Bio.Blast.NCBIXML module

Code to work with the BLAST XML output.

The BLAST XML DTD file is available on the NCBI site at: https://www.ncbi.nlm.nih.gov/dtd/NCBI_BlastOutput.dtd

Record classes to hold BLAST output are:

Classes: Blast Holds all the information from a blast search. PSIBlast Holds all the information from a psi-blast search.

Header Holds information from the header. Description Holds information about one hit description. Alignment Holds information about one alignment hit. HSP Holds information about one HSP. MultipleAlignment Holds information about a multiple alignment. DatabaseReport Holds information from the database report. Parameters Holds information from the parameters.

Bio.Blast.NCBIXML.fmt_(value, format_spec='%s', default_str='<unknown>')

  Ensure the given value formats to a string correctly.

class Bio.Blast.NCBIXML.Header

  Bases: `object`

  Saves information from a blast header.

  Members: application The name of the BLAST flavor that generated this data. version Version of blast used. date Date this data was generated. reference Reference for blast.

  query Name of query sequence. query_letters Number of letters in the query sequence. (int)

  database Name of the database. database_sequences Number of sequences in the database. (int) database_letters Number of letters in the database. (int)

  __init__()

    Initialize the class.

  __firstlineno__ = 47
  __static_attributes__ = ('application', 'database', 'database_letters', 'database_sequences', 'date', 'query', 'query_letters', 'reference', 'version')

class Bio.Blast.NCBIXML.Description

  Bases: `object`

  Stores information about one hit in the descriptions section.

  Members: title Title of the hit. score Number of bits. (int) bits Bit score. (float) e E value. (float) num_alignments Number of alignments for the same subject. (int)

  __init__()

    Initialize the class.

  __str__()

    Return the description as a string.

  __firstlineno__ = 80
  __static_attributes__ = ('bits', 'e', 'num_alignments', 'score', 'title')

class Bio.Blast.NCBIXML.DescriptionExt

  Bases: `Description`

  Extended description record for BLASTXML version 2.

  Members: items List of DescriptionExtItem

  __init__()

    Initialize the class.

  append_item(item)

    Add a description extended record.

  __annotations__ = {}
  __firstlineno__ = 104
  __static_attributes__ = ('items', 'title')

class Bio.Blast.NCBIXML.DescriptionExtItem

  Bases: `object`

  Stores information about one record in hit description for BLASTXML version 2.

  Members: id Database identifier title Title of the hit.

  __init__()

    Initialize the class.

  __str__()

    Return the description identifier and title as a string.

  __firstlineno__ = 124
  __static_attributes__ = ('accession', 'id', 'sciname', 'taxid', 'title')

class Bio.Blast.NCBIXML.Alignment

  Bases: `object`

  Stores information about one hit in the alignments section.

  Members: title Name. hit_id Hit identifier. (str) hit_def Hit definition. (str) length Length. (int) hsps A list of HSP objects.

  __init__()

    Initialize the class.

  __str__()

    Return the BLAST alignment as a formatted string.

  __firstlineno__ = 145
  __static_attributes__ = ('hit_def', 'hit_id', 'hsps', 'length', 'title')

class Bio.Blast.NCBIXML.HSP

  Bases: `object`

  Stores information about one hsp in an alignment hit.

  Members:

    - score BLAST score of hit. (float)

    - bits Number of bits for that score. (float)

    - expect Expect value. (float)

    - num_alignments Number of alignments for same subject. (int)

    - identities Number of identities (int) if using the XML parser. Tuple of number of identities/total aligned (int, int) if using the (obsolete) plain text parser.

    - positives Number of positives (int) if using the XML parser. Tuple of number of positives/total aligned (int, int) if using the (obsolete) plain text parser.

    - gaps Number of gaps (int) if using the XML parser. Tuple of number of gaps/total aligned (int, int) if using the (obsolete) plain text parser.

    - align_length Length of the alignment. (int)

    - strand Tuple of (query, target) strand.

    - frame Tuple of 1 or 2 frame shifts, depending on the flavor.

    - query The query sequence.

    - query_start The start residue for the query sequence. (1-based)

    - query_end The end residue for the query sequence. (1-based)

    - match The match sequence.

    - sbjct The sbjct sequence.

    - sbjct_start The start residue for the sbjct sequence. (1-based)

    - sbjct_end The end residue for the sbjct sequence. (1-based)

  Not all flavors of BLAST return values for every attribute:

                score     expect     identities   positives    strand  frame
      BLASTP     X          X            X            X
      BLASTN     X          X            X            X          X
      BLASTX     X          X            X            X                  X
      TBLASTN    X          X            X            X                  X
      TBLASTX    X          X            X            X                 X/X

  Note: for BLASTX, the query sequence is shown as a protein sequence, but the numbering is based on the nucleotides. Thus, the numbering is 3x larger than the number of amino acid residues. A similar effect can be seen for the sbjct sequence in TBLASTN, and for both sequences in TBLASTX.

  Also, for negative frames, the sequence numbering starts from query_start and counts down.

  __init__()

    Initialize the class.

  __str__()

    Return the BLAST HSP as a formatted string.

  __firstlineno__ = 172
  __static_attributes__ = ('align_length', 'bits', 'expect', 'frame', 'gaps', 'identities', 'match', 'num_alignments', 'positives', 'query', 'query_end', 'query_start', 'sbjct', 'sbjct_end', 'sbjct_start', 'score', 'strand')

class Bio.Blast.NCBIXML.MultipleAlignment

  Bases: `object`

  Holds information about a multiple alignment.

  Members: alignment A list of tuples (name, start residue, sequence, end residue).

  The start residue is 1-based. It may be blank, if that sequence is not aligned in the multiple alignment.

  __init__()

    Initialize the class.

  to_generic()

    Retrieve generic alignment object for the given alignment.

    Instead of the tuples, this returns a MultipleSeqAlignment object from Bio.Align, through which you can manipulate and query the object.

    Thanks to James Casbon for the code.

  __firstlineno__ = 276
  __static_attributes__ = ('alignment',)

class Bio.Blast.NCBIXML.Round

  Bases: `object`

  Holds information from a PSI-BLAST round.

  Members: number Round number. (int) reused_seqs Sequences in model, found again. List of Description objects. new_seqs Sequences not found, or below threshold. List of Description. alignments A list of Alignment objects. multiple_alignment A MultipleAlignment object.

  __init__()

    Initialize the class.

  __firstlineno__ = 322
  __static_attributes__ = ('alignments', 'multiple_alignment', 'new_seqs', 'number', 'reused_seqs')

class Bio.Blast.NCBIXML.DatabaseReport

  Bases: `object`

  Holds information about a database report.

  Members: database_name List of database names. (can have multiple dbs) num_letters_in_database Number of letters in the database. (int) num_sequences_in_database List of number of sequences in the database. posted_date List of the dates the databases were posted. ka_params A tuple of (lambda, k, h) values. (floats) gapped # XXX this isn’t set right! ka_params_gap A tuple of (lambda, k, h) values. (floats)

  __init__()

    Initialize the class.

  __firstlineno__ = 342
  __static_attributes__ = ('database_name', 'gapped', 'ka_params', 'ka_params_gap', 'num_letters_in_database', 'num_sequences_in_database', 'posted_date')

class Bio.Blast.NCBIXML.Parameters

  Bases: `object`

  Holds information about the parameters.

  Members: matrix Name of the matrix. gap_penalties Tuple of (open, extend) penalties. (floats) sc_match Match score for nucleotide-nucleotide comparison sc_mismatch Mismatch penalty for nucleotide-nucleotide comparison num_hits Number of hits to the database. (int) num_sequences Number of sequences. (int) num_good_extends Number of extensions. (int) num_seqs_better_e Number of sequences better than e-value. (int) hsps_no_gap Number of HSP’s better, without gapping. (int) hsps_prelim_gapped Number of HSP’s gapped in prelim test. (int) hsps_prelim_gapped_attemped Number of HSP’s attempted in prelim. (int) hsps_gapped Total number of HSP’s gapped. (int) query_length Length of the query. (int) query_id Identifier of the query sequence. (str) database_length Number of letters in the database. (int) effective_hsp_length Effective HSP length. (int) effective_query_length Effective length of query. (int) effective_database_length Effective length of database. (int) effective_search_space Effective search space. (int) effective_search_space_used Effective search space used. (int) frameshift Frameshift window. Tuple of (int, float) threshold Threshold. (int) window_size Window size. (int) dropoff_1st_pass Tuple of (score, bits). (int, float) gap_x_dropoff Tuple of (score, bits). (int, float) gap_x_dropoff_final Tuple of (score, bits). (int, float) gap_trigger Tuple of (score, bits). (int, float) blast_cutoff Tuple of (score, bits). (int, float)

  __init__()

    Initialize the class.

  __firstlineno__ = 367
  __static_attributes__ = ('blast_cutoff', 'database_length', 'dropoff_1st_pass', 'effective_database_length', 'effective_hsp_length', 'effective_query_length', 'effective_search_space', 'effective_search_space_used', 'frameshift', 'gap_penalties', 'gap_trigger', 'gap_x_dropoff', 'gap_x_dropoff_final', 'hsps_gapped', 'hsps_no_gap', 'hsps_prelim_gapped', 'hsps_prelim_gapped_attemped', 'matrix', 'num_good_extends', 'num_hits', 'num_seqs_better_e', 'num_sequences', 'query_id', 'query_length', 'sc_match', 'sc_mismatch', 'threshold', 'window_size')

class Bio.Blast.NCBIXML.Blast

  Bases: `Header`, `DatabaseReport`, `Parameters`

  Saves the results from a blast search.

  Members: descriptions A list of Description objects. alignments A list of Alignment objects. multiple_alignment A MultipleAlignment object. + members inherited from base classes

  __init__()

    Initialize the class.

  __annotations__ = {}
  __firstlineno__ = 434
  __static_attributes__ = ('alignments', 'descriptions', 'multiple_alignment')

class Bio.Blast.NCBIXML.PSIBlast

  Bases: `Header`, `DatabaseReport`, `Parameters`

  Saves the results from a blastpgp search.

  Members: rounds A list of Round objects. converged Whether the search converged. + members inherited from base classes

  __init__()

    Initialize the class.

  __annotations__ = {}
  __firstlineno__ = 455
  __static_attributes__ = ('converged', 'rounds')

class Bio.Blast.NCBIXML.BlastParser(debug=0)

  Bases: `_XMLparser`

  Parse XML BLAST data into a Blast object.

  Parses XML output from BLAST (direct use discouraged). This (now) returns a list of Blast records. Historically it returned a single Blast record. You are expected to use this via the parse or read functions.

  All XML ‘action’ methods are private methods and may be:

  - `_start_TAG` called when the start tag is found

  - `_end_TAG` called when the end tag is found

  __init__(debug=0)

    Initialize the parser.

    Arguments:

      - debug - integer, amount of debug information to print

  reset()

    Reset all the data allowing reuse of the BlastParser() object.

  set_hit_id()

    Record the identifier of the database sequence (PRIVATE).

  set_hit_def()

    Record the definition line of the database sequence (PRIVATE).

  set_hit_accession()

    Record the accession value of the database sequence (PRIVATE).

  set_hit_len()

    Record the length of the hit.

  __firstlineno__ = 580
  __static_attributes__ = ('_blast', '_descr', '_header', '_hit', '_hit_descr_item', '_hsp', '_method_map', '_method_name_level', '_mult_al', '_parameters', '_parser', '_records', '_value', '_xml_version')

Bio.Blast.NCBIXML.read(handle, debug=0)

  Return a single Blast record (assumes just one query).

  Uses the BlastParser internally.

  This function is for use when there is one and only one BLAST result in your XML file.

  Use the Bio.Blast.NCBIXML.parse() function if you expect more than one BLAST record (i.e. if you have more than one query sequence).

Bio.Blast.NCBIXML.parse(handle, debug=0)

  Return an iterator a Blast record for each query.

  Incremental parser, this is an iterator that returns Blast records. It uses the BlastParser internally.

  handle - file handle to and XML file to parse debug - integer, amount of debug information to print

  This is a generator function that returns multiple Blast records objects - one for each query sequence given to blast. The file is read incrementally, returning complete records as they are read in.

  Should cope with new BLAST 2.2.14+ which gives a single XML file for multiple query records.

  Should also cope with XML output from older versions BLAST which gave multiple XML files concatenated together (giving a single file which strictly speaking wasn’t valid XML).

Biopython v: 1.85

Versions
  Previous
  Latest
  Develop

Biopython Project
  Homepage
  On GitHub