
 Ic        	   @   s  d  Z  d d l m Z d d l Z d d l m Z d e f d     YZ d e f d     YZ d	 d
  Z	 d	 d  Z
 e d k rd d l Z d d l Z e e j d  Z e
 e  Z x2e D]*Z d Ge j GHd e e j  e d   g  e j D] Z e e j  ^ q  f GHx9 e j D]. Z e j d  Ge j Gd Ge e j  Gd GHqWd Z x e j D] Z x| e j D]q Z e j e k  rd GHd Ge j GHd Ge j GHd Ge j GHe j d  d GHe j  d  d GHe j! d  d GHn  qqWqaWq Wn  d S(   s  This module provides code to work with the BLAST XML output
following the DTD available on the NCBI FTP
ftp://ftp.ncbi.nlm.nih.gov/blast/documents/xml/NCBI_BlastOutput.dtd

Classes:
BlastParser         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 function.

_XMLParser          Generic SAX parser (private).

Functions:
parse               Incremental parser, this is an iterator that returns
                    Blast records.  It uses the BlastParser internally.
i(   t   RecordN(   t   ContentHandlert
   _XMLparserc           B   s>   e  Z d  Z d d  Z d   Z d   Z d   Z d   Z RS(   s}   Generic SAX Parser

    Just a very basic SAX parser.

    Redefine the methods startElement, characters and endElement.
    i    c         C   s(   g  |  _  d |  _ | |  _ g  |  _ d S(   sS   Constructor

        debug - integer, amount of debug information to print
        t    N(   t   _tagt   _valuet   _debugt   _debug_ignore_list(   t   selft   debug(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   __init__"   s    			c         C   s   | j  d d  S(   sQ   Removes 'dangerous' from tag names

        name -- name to be 'secured'
        t   -t   _(   t   replace(   R   t   name(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _secure_name,   s    c         C   s   |  j  j |  |  j d |  } t |  |  r^ t d |  |  j d k r d | GHq n= | |  j k r |  j d k r d | GHn  |  j j |  n  d S(   s   Found XML start tag

        No real need of attr, BLAST DTD doesn't use them

        name -- name of the tag

        attr -- tag attributes
        t   _start_s	   self.%s()i   s   NCBIXML: Parsed:  i   s   NCBIXML: Ignored: N(   R   t   appendR   t   hasattrt   evalR   R   (   R   R   t   attrt   method(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   startElement4   s    	c         C   s   |  j  | 7_  d S(   s7   Found some text

        ch -- characters read
        N(   R   (   R   t   ch(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt
   charactersO   s    c         C   s   |  j  j   |  _  |  j d |  } t |  |  rg t d |  |  j d k r d | G|  j  GHq nD | |  j k r |  j d k r d | G|  j  GHn  |  j j |  n  d |  _  d S(	   s4   Found XML end tag

        name -- tag name
        t   _end_s	   self.%s()i   s   NCBIXML: Parsed:  i   s   NCBIXML: Ignored: R   N(   R   t   stripR   R   R   R   R   R   (   R   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt
   endElementV   s    (   t   __name__t
   __module__t   __doc__R
   R   R   R   R   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyR      s   
			t   BlastParserc           B   s  e  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d    Z! d!   Z" d"   Z# d#   Z$ d$   Z% d%   Z& d&   Z' d'   Z( d(   Z) d)   Z* d*   Z+ d+   Z, d,   Z- d-   Z. d.   Z/ d/   Z0 d0   Z1 d1   Z2 d2   Z3 d3   Z4 d4   Z5 d5   Z6 RS(6   s   Parse XML BLAST data into a Record.Blast object

    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
    i    c         C   s   t  j |  |  t j j   |  _ |  j j |   |  j j t j j j	 d  |  j j t j j j
 d  |  j j t j j j d  |  j j t j j j d  |  j   d S(   sS   Constructor

        debug - integer, amount of debug information to print
        i    N(   R   R
   t   xmlt   saxt   make_parsert   _parsert   setContentHandlert
   setFeaturet   handlert   feature_validationt   feature_namespacest   feature_external_pest   feature_external_gest   reset(   R   R	   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyR
   x   s    c         C   s7   g  |  _  t j   |  _ t j   |  _ d |  j _ d S(   s=   Reset all the data allowing reuse of the BlastParser() objectN(   t   _recordsR    t   Headert   _headert
   Parameterst   _parameterst   Nonet   filter(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyR+      s    	c         C   s   t  j   |  _ d  S(   N(   R    t   Blastt   _blast(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _start_Iteration   s    c         C   s  |  j  j |  j _ |  j  j |  j _ |  j  j |  j _ |  j  j |  j _ |  j  j |  j _ t |  j d  sz |  j j r |  j  j |  j _ n  t |  j d  s |  j j	 r |  j  j	 |  j _	 n  t |  j d  s |  j j
 r |  j  j
 |  j _
 n  |  j j
 |  j _ |  j j |  j _ |  j j |  j _ |  j j |  j _ |  j j |  j _ |  j j |  j _ |  j j |  j _ |  j j |  j _ |  j j |  j _ |  j j |  j  d  |  _ |  j rn  d  S(   Nt   queryt   query_idt   query_letters(   R.   t	   referenceR4   t   datet   versiont   databaset   applicationR   R6   R7   R8   t   query_lengtht   num_letters_in_databaset   database_lengthR0   t   matrixt   num_seqs_better_et   gap_penaltiesR2   t   expectt   sc_matcht   sc_mismatchR,   R   R1   R   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Iteration   s6    		 c         C   s   |  j  j   |  j _ d S(   sh   BLAST program, e.g., blastp, blastn, etc.

        Save this to put on each blast record object
        N(   R   t   upperR.   R=   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_BlastOutput_program   s    c         C   s   |  j  j   } | d |  j _ t |  d k r | d d d k rs | d d d k rs | d d d !|  j _ q | d |  j _ n  d S(	   s   version number and date of the BLAST engine.

        e.g. "BLASTX 2.2.12 [Aug-07-2005]" but there can also be
        variants like "BLASTP 2.2.18+" without the date.

        Save this to put on each blast record object
        i   i   i   i    t   [it   ]N(   R   t   splitR.   R;   t   lenR:   (   R   t   parts(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_BlastOutput_version   s    (c         C   s   |  j  |  j _ d S(   sr   a reference to the article describing the algorithm

        Save this to put on each blast record object
        N(   R   R.   R9   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_BlastOutput_reference   s    c         C   s   |  j  |  j _ d S(   sW   the database(s) searched

        Save this to put on each blast record object
        N(   R   R.   R<   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_BlastOutput_db   s    c         C   s   |  j  |  j _ d S(   s   the identifier of the query

        Important in old pre 2.2.14 BLAST, for recent versions
        <Iteration_query-ID> is enough
        N(   R   R.   R7   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_BlastOutput_query_ID   s    c         C   s   |  j  |  j _ d S(   s   the definition line of the query

        Important in old pre 2.2.14 BLAST, for recent versions
        <Iteration_query-def> is enough
        N(   R   R.   R6   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_BlastOutput_query_def   s    c         C   s   t  |  j  |  j _ d S(   s   the length of the query

        Important in old pre 2.2.14 BLAST, for recent versions
        <Iteration_query-len> is enough
        N(   t   intR   R.   R8   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_BlastOutput_query_len  s    c         C   s   |  j  |  j _ d S(   s$   the identifier of the query
        N(   R   R4   R7   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Iteration_query_ID  s    c         C   s   |  j  |  j _ d S(   s)   the definition line of the query
        N(   R   R4   R6   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Iteration_query_def  s    c         C   s   t  |  j  |  j _ d S(   s    the length of the query
        N(   RT   R   R4   R8   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Iteration_query_len  s    c         C   s   t  |  j  |  j _ d S(   s?   hits to the database sequences, one for every sequence
        N(   RT   R   R4   t   num_hits(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_BlastOutput_hits)  s    c         C   s   |  j  |  j _ d S(   s   matrix used (-M)
        N(   R   R0   RA   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Parameters_matrix4  s    c         C   s   |  j  |  j _ d S(   s"   expect values cutoff (-e)
        N(   R   R0   RD   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Parameters_expect9  s    
c         C   s   t  |  j  |  j _ d S(   s?   match score for nucleotide-nucleotide comparaison (-r)
        N(   RT   R   R0   RE   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Parameters_sc_matchJ  s    c         C   s   t  |  j  |  j _ d S(   sD   mismatch penalty for nucleotide-nucleotide comparaison (-r)
        N(   RT   R   R0   RF   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Parameters_sc_mismatchO  s    c         C   s   t  |  j  |  j _ d S(   s    gap existence cost (-G)
        N(   RT   R   R0   RC   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Parameters_gap_openT  s    c         C   s%   |  j  j t |  j  f |  j  _ d S(   s    gap extension cose (-E)
        N(   R0   RC   RT   R   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Parameters_gap_extendY  s    	c         C   s   |  j  |  j _ d S(   s   filtering options (-F)
        N(   R   R0   R2   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Parameters_filter_  s    c         C   st   |  j  j j t j    |  j  j j t j    g  |  j  _ |  j  j d |  _ |  j  j d |  _	 d |  j	 _
 d  S(   Nii    (   R4   t
   alignmentsR   R    t	   Alignmentt   descriptionst   Descriptiont   multiple_alignmentt   _hitt   _descrt   num_alignments(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt
   _start_Hito  s    c         C   s"   d  |  j _ d  |  _ d  |  _ d  S(   N(   R1   R4   Rf   Rg   Rh   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hitw  s    	c         C   s&   |  j  |  j _ |  j  d |  j _ d S(   s,   identifier of the database sequence
        t    N(   R   Rg   t   hit_idt   title(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hit_id}  s    c         C   s:   |  j  |  j _ |  j j |  j  7_ |  j j |  j _ d S(   s1   definition line of the database sequence
        N(   R   Rg   t   hit_defRn   Rh   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hit_def  s    c         C   s"   |  j  |  j _ |  j  |  j _ d S(   s+   accession of the database sequence
        N(   R   Rg   t	   accessionRh   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hit_accession  s    c         C   s   t  |  j  |  j _ d  S(   N(   RT   R   Rg   t   length(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hit_len  s    c         C   sn   |  j  j j t j    |  j  j d |  _ |  j j d 7_ |  j j	 j t j
    |  j j	 d |  _ d  S(   Nii   (   Rg   t   hspsR   R    t   HSPt   _hspRh   Ri   R4   Rf   t   MultipleAlignmentt   _mult_al(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt
   _start_Hsp  s
    c         C   sC   t  |  j  |  j _ |  j j d k r? t  |  j  |  j _ n  d S(   s   raw score of HSP
        N(   t   floatR   Rx   t   scoreRh   R1   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_score  s    c         C   sC   t  |  j  |  j _ |  j j d k r? t  |  j  |  j _ n  d S(   s   bit score of HSP
        N(   R|   R   Rx   t   bitsRh   R1   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_bit_score  s    c         C   sC   t  |  j  |  j _ |  j j d k r? t  |  j  |  j _ n  d S(   s&   expect value value of the HSP
        N(   R|   R   Rx   RD   Rh   t   eR1   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_evalue  s    c         C   s   t  |  j  |  j _ d S(   sC   offset of query at the start of the alignment (one-offset)
        N(   RT   R   Rx   t   query_start(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_query_from  s    c         C   s   t  |  j  |  j _ d S(   sA   offset of query at the end of the alignment (one-offset)
        N(   RT   R   Rx   t	   query_end(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_query_to  s    c         C   s   t  |  j  |  j _ d S(   sJ   offset of the database at the start of the alignment (one-offset)
        N(   RT   R   Rx   t   sbjct_start(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_hit_from  s    c         C   s   t  |  j  |  j _ d S(   sH   offset of the database at the end of the alignment (one-offset)
        N(   RT   R   Rx   t	   sbjct_end(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_hit_to  s    c         C   s   t  |  j  f |  j _ d S(   s)   frame of the query if applicable
        N(   RT   R   Rx   t   frame(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_query_frame  s    c         C   s"   |  j  j t |  j  f 7_ d S(   s5   frame of the database sequence if applicable
        N(   Rx   R   RT   R   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_hit_frame  s    c         C   s   t  |  j  |  j _ d S(   s.   number of identities in the alignment
        N(   RT   R   Rx   t
   identities(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_identity  s    c         C   s   t  |  j  |  j _ d S(   sI   number of positive (conservative) substitutions in the alignment
        N(   RT   R   Rx   t	   positives(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_positive  s    c         C   s   t  |  j  |  j _ d S(   s(   number of gaps in the alignment
        N(   RT   R   Rx   t   gaps(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_gaps  s    c         C   s   t  |  j  |  j _ d S(   s    length of the alignment
        N(   RT   R   Rx   t   align_length(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_align_len  s    c         C   s   |  j  |  j _ d S(   s'   alignment string for the query
        N(   R   Rx   R6   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_qseq  s    c         C   s   |  j  |  j _ d S(   s*   alignment string for the database
        N(   R   Rx   t   sbjct(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_hseq  s    c         C   s   |  j  |  j _ d S(   s@   Formatting middle line as normally seen in BLAST report
        N(   R   Rx   t   match(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Hsp_midline  s    c         C   s   t  |  j  |  j _ d S(   s,   number of sequences in the database
        N(   RT   R   R4   t   num_sequences_in_database(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Statistics_db_num  s    c         C   s   t  |  j  |  j _ d S(   s*   number of letters in the database
        N(   RT   R   R4   R?   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Statistics_db_len	  s    c         C   s   t  |  j  |  j _ d S(   s!   the effective HSP length
        N(   RT   R   R4   t   effective_hsp_length(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Statistics_hsp_len  s    c         C   s   t  |  j  |  j _ d S(   s#   the effective search space
        N(   R|   R   R4   t   effective_search_space(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Statistics_eff_space  s    c         C   s   t  |  j  |  j _ d S(   s$   Karlin-Altschul parameter K
        N(   R|   R   R4   t	   ka_params(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Statistics_kappa  s    c         C   s%   t  |  j  |  j j f |  j _ d S(   s)   Karlin-Altschul parameter Lambda
        N(   R|   R   R4   R   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Statistics_lambda  s    c         C   s&   |  j  j t |  j  f |  j  _ d S(   s$   Karlin-Altschul parameter H
        N(   R4   R   R|   R   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   _end_Statistics_entropy#  s    (7   R   R   R   R
   R+   R5   RG   RI   RO   RP   RQ   RR   RS   RU   RV   RW   RX   RZ   R[   R\   R]   R^   R_   R`   Ra   Rj   Rk   Ro   Rq   Rs   Ru   R{   R~   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyR   p   sj   			6																									
													
									i    c         C   s   t  |  |  } y | j   } Wn t k
 r8 d } n X| d k rT t d   n  y | j   } Wn t k
 r} d } n X| d k	 r t d   n  | S(   s&  Returns a single Blast record (assumes just one query).

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

   s   No records found in handles$   More than one record found in handleN(   t   parset   nextt   StopIterationR1   t
   ValueError(   t   handleR	   t   iteratort   firstt   second(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   read(  s    


c         c   s  d d l  m } d } d } d } |  j |  } d } | sL t d   n  x| rQ| j |  sw t d |   n  | j   } t |  }	 |	 j | _ |	 j	 | _
 |	 j | _ | j | t  x/ |	 j r |	 j d	 }
 |	 j d
 |	 _ |
 Vq Wx)t r | |  j |  d } } | s2| j d t  Pn  |  j |  } | | j d |  d k r| j | t  x |	 j r|	 j d	 }
 |	 j d
 |	 _ |
 VqqWq | | j d | d
  \ } } | | } | j | t  x/ |	 j r|	 j d	 }
 |	 j d
 |	 _ |
 VqW| d } } Pq W| d k s3t  t |	 j  d	 k sO t  qO W| d k sdt  | d k svt  t |	 j  d	 k st  d S(   s  Returns an iterator a Blast record for each query.

    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 mutliple 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).i(   t   expati   i
   s   <?xmlR   s   Your XML file was emptys&   Your XML file did not start with %s...i    i   s   
N(   t   xml.parsersR   R   R   t
   startswitht   ParserCreateR   R   t   StartElementHandlerR   t   EndElementHandlerR   t   CharacterDataHandlert   Parset   FalseR,   t   Truet   findRL   t   AssertionErrorRM   (   R   R	   R   t   BLOCKt   MARGINt	   XML_STARTt   textt   pendingt   expat_parsert   blast_parsert   record(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyR   B  s`    			 
	t   __main__i   s   Blast ofs+   Found %s alignments with a total of %s HSPsc         C   s   |  | S(   N(    (   t   at   b(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   <lambda>  s    i2   t   bpt   HSPsg{Gz?s   *****t   sequenceRt   s   e valueiK   s   ...("   R   t	   Bio.BlastR    t   xml.saxR    t   xml.sax.handlerR   R   R   R   R   R   t   syst   ost   opent   argvR   t   r_listt   rR6   RM   Rb   t   reduceR   Rv   t   alRn   Rt   t   E_VALUE_THRESHt	   alignmentt   hspRD   R   R   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIXML.pyt   <module>   s>   U `	+,