
>mIc           @   s!  d  Z  d d l Z d d l Z d d l m Z d d l Td d l m Z d e f d     YZ	 d e f d	     YZ
 d
 f  d     YZ d e f d     YZ d e f d     YZ d f  d     YZ d f  d     YZ d f  d     YZ d f  d     YZ d f  d     YZ d f  d     YZ d e e e e e e e f d     YZ d e e e e e e e f d     YZ d  f  d!     YZ d" d#  Z d" d$  Z d" d%  Z d&   Z e i  d'  Z d(   Z d)   Z  d*   Z! d+   Z" d,   Z# d- e f d.     YZ$ d/ e f d0     YZ% d S(1   sb  
This module provides code to work with the standalone version of
BLAST, either blastall or blastpgp, provided by the NCBI.
http://www.ncbi.nlm.nih.gov/BLAST/

Classes:
LowQualityBlastError     Except that indicates low quality query sequences.
BlastParser              Parses output from blast.
BlastErrorParser         Parses output and tries to diagnose possible errors.
PSIBlastParser           Parses output from psi-blast.
Iterator                 Iterates over a file of blast results.

_Scanner                 Scans output from standalone BLAST.
_BlastConsumer           Consumes output from blast.
_PSIBlastConsumer        Consumes output from psi-blast.
_HeaderConsumer          Consumes header information.
_DescriptionConsumer     Consumes description information.
_AlignmentConsumer       Consumes alignment information.
_HSPConsumer             Consumes hsp information.
_DatabaseReportConsumer  Consumes database report information.
_ParametersConsumer      Consumes parameters information.

Functions:
blastall        Execute blastall.
blastpgp        Execute blastpgp.
rpsblast        Execute rpsblast.

iN(   t   File(   t   *(   t   Recordt   LowQualityBlastErrorc           B   s   e  Z d  Z RS(   so  Error caused by running a low quality sequence through BLAST.

    When low quality sequences (like GenBank entries containing only
    stretches of a single nucleotide) are BLASTed, they will result in
    BLAST generating an error and not being able to perform the BLAST.
    search. This error should be raised for the BLAST reports produced
    in this case.
    (   t   __name__t
   __module__t   __doc__(    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR   -   s   t   ShortQueryBlastErrorc           B   s   e  Z d  Z RS(   s  Error caused by running a short query sequence through BLAST.

    If the query sequence is too short, BLAST outputs warnings and errors:
    Searching[blastall] WARNING:  [000.000]  AT1G08320: SetUpBlastSearch failed.
    [blastall] ERROR:  [000.000]  AT1G08320: Blast: 
    [blastall] ERROR:  [000.000]  AT1G08320: Blast: Query must be at least wordsize
    done

    This exception is raised when that condition is detected.

    (   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/NCBIStandalone.pyR   8   s   t   _Scannerc           B   s   e  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 RS(   s   Scan BLAST output from blastall or blastpgp.

    Tested with blastall and blastpgp v2.0.10, v2.0.11

    Methods:
    feed     Feed data into the scanner.
    
    c         C   s   t  | t j  r | } n t j |  } t | | j d d |  j | |  |  j | |  |  j | |  |  j | |  d S(   s   S.feed(handle, consumer)

        Feed in a BLAST report for scanning.  handle is a file-like
        object that contains the BLAST report.  consumer is a Consumer
        object that will receive events as the report is scanned.

        t   containst   BLASTN(	   t
   isinstanceR    t
   UndoHandlet   read_and_call_untilt   noeventt   _scan_headert   _scan_roundst   _scan_database_reportt   _scan_parameters(   t   selft   handlet   consumert   uhandle(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyt   feedP   s    	c         C   s  | j    t | | j d d t | | j d d t | | j d d xl t | | j d d r xM | j   } t |  r | j |  Pqj | j	 d  r Pqj | j |  qj WqO Wt | | j d d t | | j d d	 t | | j d d t | | j d d rDt
 | | j d d t | | j d d n  t | | j d d rt
 | | j d d t | | j d d n  | j   } | j   d
 k st  | j	 d	  st  | j	 d  r[t | | j d d t
 | | j d d t | | j d d t
 | | j d d t | | j d d t | | j d d n | j	 d  rt
 | | j d d t | | j d d t | | j d d t | | j d d t
 | | j d d t | | j d d n t d   | j   d  S(   NR	   R
   t   blanki   t   starts   <pre>t	   Referencet   RIDs   RID:t    s   Query=t   ends   total letterst	   sequencess	   Database:s   Invalid header?(   t   start_headert   read_and_callt   versiont   read_and_call_whileR   t   attempt_read_and_callt	   referencet   readlinet   is_blank_linet
   startswithR   t   peeklinet   stript   AssertionErrort
   query_infot   database_infot
   ValueErrort
   end_header(   R   R   R   t   line(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR   e   sX    ,
	c         C   s   x t  |  } | j d  r` | j d  r` t j d |  d  k r` | j d  d k r` Pn  |  j | |  |  j | |  q Wd  S(   Nt	   Searchings   Results from rounds   Score +Es   No hits foundi(   t   safe_peeklineR'   t   ret   searcht   Nonet   findt   _scan_descriptionst   _scan_alignments(   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/NCBIStandalone.pyR      s    c         C   s  | j    t | | j d d | j   s? t d d   n  | j   } | j d  d k so | j d  r t | | j d d t | | j d d n  t | | j d	 d
 t | | j	 d d r t | | j d	 d
 n  t | | j
 d t j d  s@t | | j d d t | | j d	 d
 | j   d  St | | j
 d d t | | j d d t | | j d	 d
 | j   j d  st | | j d	 d
 t | | j d	 d
 n  t | | j d d rbt | | j d	 d
 t |  } | j d  rb| d d k rb| j d  rbt | | j d	 d
 t | | j d	 d
 qbn  t | | j d d t | | j d	 d
 | j   d  S(   NR   R0   s!   Unexpected end of blast report.  s*   Looks suspiciously like a PSI-BLAST crash.s   ERROR:it   doneR	   R   i   t   Resultst   has_res   Score +Es   No hits founds   Sequences producings   Sequences used in models   Sequences not foundt	   CONVERGEDi    t   >t   QUERY(   t   start_descriptionsR#   R   R(   R-   R5   R'   R"   R    t   roundt   description_headerR2   t   compilet   no_hitst   end_descriptionst   model_sequencesR   t   descriptiont   nonmodel_sequencesR1   t	   converged(   R   R   R   R/   t   l(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR6      sN    

$	
	 c         C   sl   t  | | j d d t |  } | j d  r5 d  S| d d k rX |  j | |  n |  j | |  d  S(   NR   t
   ALIGNMENTSs
     Databasei    R<   (   R#   R   R1   R'   t   _scan_pairwise_alignmentst   _scan_masterslave_alignment(   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/NCBIStandalone.pyR7   f  s    c         C   s;   x4 t  |  } | d d k r# Pn  |  j | |  q Wd  S(   Ni    R<   (   R1   t   _scan_one_pairwise_alignment(   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/NCBIStandalone.pyRJ   u  s
    c         C   s^   | j    |  j | |  x3 t |  } | j d  s< Pn  |  j | |  q W| j   d  S(   Ns    Score(   t   start_alignmentt   _scan_alignment_headerR1   R'   t	   _scan_hspt   end_alignment(   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/NCBIStandalone.pyRL   |  s    
c         C   s   t  | | j d d xs t |  } | j   j d  sO | j   j d  r` | j |  Pn t |  r{ t d   n  | j |  q Wt | | j	 d d s t  | | j	 d d n  d  S(	   NR   R<   s   Length =s   Length=s*   I missed the Length in an alignment headers
             R   i   (
   R    t   titlet   safe_readlinet   lstripR'   t   lengthR&   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/NCBIStandalone.pyRN     s    	c         C   s8   | j    |  j | |  |  j | |  | j   d  S(   N(   t	   start_hspt   _scan_hsp_headert   _scan_hsp_alignmentt   end_hsp(   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/NCBIStandalone.pyRO     s    
c         C   sr   t  | | j d d t  | | j d d t | | j d d t | | j d d t  | | j d d d  S(   NR   s    Scores    Identitiess    Strands    FrameR   i   (   R    t   scoret
   identitiesR#   t   strandt   frameR   (   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/NCBIStandalone.pyRV     s
    c         C   s   x t  | | j d d t | | j d d t | | j d d t | | j d d t | | j d d t |  } | j d  p | j d  s Pq q Wd  S(   NR   s        t   Queryt   SbjctR   i   (	   R#   R   R    t   queryt   alignt   sbjctR"   R1   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/NCBIStandalone.pyRW     s    
c         C   s   | j    x t |  } | j d  s7 | j d  rH | j |  Pq | j d  rh | j |  Pq t |  r | j |  q | j |  q Wt | | j d d | j   d  S(   NR0   s   Results from rounds
     DatabaseR   i   (	   RM   RR   R'   t   savelineR&   R   t	   multalignR"   RP   (   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/NCBIStandalone.pyRK     s    
c         C   s  | j    t | | j d d rg t | | j d d t | | j d d t | | j d d n  x t | | j d d r?| j   s | j   d  St | | j d d t | | j d d t | | j	 d d	 t | | j
 d d
 t | | j d d t |  } | j |  | j d  d k rj Pqj qj Wt | | j d d t | | j  t | | j d d t | | j d d t | | j d d rt | | j  n  y t | | j d d Wn+ t k
 r} t |  d k r  qn X| j   d  S(   NR   s     SubsetR	   t   lettersR   s     s
     Databases
       Posteds     Number of letterss     Number of sequencest   LambdaiR   i   t   Gappeds   Unexpected end of stream.(   t   start_database_reportR#   R   R    t   databaseR(   t   end_database_reportR   t   posted_datet   num_letters_in_databaset   num_sequences_in_databaseRR   Rb   R5   t	   ka_paramst   gappedt   ka_params_gapR"   R-   t   str(   R   R   R   R/   t   x(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR     sB    
	

c         C   s  | j    s d  S| j   t | | j d d t | | j d d t | | j d d t | | j d d t | | j d d t | | j d d t | | j	 d d t | | j
 d d t | | j d d	 rnt | | j d d
 r)t | | j d d t | | j d d qt | | j d d t | | j d d t | | j d d n1 t | | j d d rt | | j d d n  t | | j d t j d  t | | j d t j d  t | | j d d t | | j d d t | | j d t j d  t | | j d t j d  t | | j d t j d  t | | j d t j d  t | | j d d t | | j d d t | | j d d t | | j d d t | | j d d t | | j d d t | | j d d t | | j d d t | | j d d  t  | j    d! d" s|t | | j! d d# n  | j"   d  S($   NR   t   Matrixt   Gaps   Number of Sequencess   Number of Hitss   Number of extensionss   Number of successfuls   Number of sequencess   Number of HSP's betters   Number of HSP's gapped:s   Number of HSP's successfullys!   Number of extra gapped extensionss   Number of HSP's thats   Number of HSP's gappedR:   s   [Ll]ength of querys   [Ll]ength of \s*[Dd]atabases   Length adjustments   effective HSPs   [Ee]ffective length of querys%   [Ee]ffective length of \s*[Dd]atabases   [Ee]ffective search space:s   [Ee]ffective search space usedt
   frameshiftt   Ts   Neighboring words thresholdt   As   Window for multiple hitst   X1t   X2t   X3t   S1t   allow_spacesi   t   S2(#   R(   t   start_parametersR#   t   matrixt   gap_penaltiest   num_sequencesR    t   num_hitst   num_extendst   num_good_extendst   num_seqs_better_et   hsps_no_gapR   t   hsps_prelim_gappedt   hsps_prelim_gap_attemptedt   hsps_gappedt   query_lengthR2   RA   t   database_lengtht   effective_hsp_lengtht   effective_query_lengtht   effective_database_lengtht   effective_search_spacet   effective_search_space_usedRt   t	   thresholdt   window_sizet   dropoff_1st_passt   gap_x_dropofft   gap_x_dropoff_finalt   gap_triggerR&   t   blast_cutofft   end_parameters(   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/NCBIStandalone.pyR   >  s    9
		

	
(   R   R   R   R   R   R   R6   R7   RJ   RL   RN   RO   RV   RW   RK   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/NCBIStandalone.pyR   G   s   		t		z									Vt   BlastParserc           B   s    e  Z d  Z d   Z d   Z RS(   s3   Parses BLAST data into a Record.Blast object.

    c         C   s   t    |  _ t   |  _ d S(   s   __init__(self)N(   R   t   _scannert   _BlastConsumert	   _consumer(   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/NCBIStandalone.pyt   __init__  s    c         C   s    |  j  j | |  j  |  j j S(   s   parse(self, handle)(   R   R   R   t   data(   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/NCBIStandalone.pyt   parse  s    (   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/NCBIStandalone.pyR     s   	t   PSIBlastParserc           B   s    e  Z d  Z d   Z d   Z RS(   s6   Parses BLAST data into a Record.PSIBlast object.

    c         C   s   t    |  _ t   |  _ d S(   s   __init__(self)N(   R   R   t   _PSIBlastConsumerR   (   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/NCBIStandalone.pyR     s    c         C   s    |  j  j | |  j  |  j j S(   s   parse(self, handle)(   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/NCBIStandalone.pyR     s    (   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/NCBIStandalone.pyR     s   	t   _HeaderConsumerc           B   s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   s   t  j   |  _ d  S(   N(   R   t   Headert   _header(   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/NCBIStandalone.pyR     s    c         C   sG   | j    } | d |  j _ | d |  j _ | d d d !|  j _ d  S(   Ni    i   i   i(   t   splitR   t   applicationR!   t   date(   R   R/   t   c(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR!     s    c         C   s<   | j  d  r" | d |  j _ n |  j j | |  j _ d  S(   Ns   Reference: i   (   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/NCBIStandalone.pyR$   
  s    c         C   s   | j  d  r" | d |  j _ nY | j  d  sP d |  j j | f |  j _ n+ t d | d |  \ } t |  |  j _ d  S(   Ns   Query= i   s          s   %s%ss   ([0-9,]+) letterss1   I could not find the number of letters in line
%s(   R'   R   R_   t
   _re_searcht	   _safe_intt   query_letters(   R   R/   Rd   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR+     s    c         C   s   | j    } | j d  r. | d |  j _ nn | j d  s\ |  j j | j   |  j _ n@ t d | d |  \ } } t |  |  j _ t |  |  j _	 d  S(   Ns
   Database: i
   s   total letterss-   ([0-9,]+) sequences; ([0-9,-]+) total letterss5   I could not find the sequences and letters in line
%s(
   t   rstripR'   R   Rh   t   endswithR)   R   R   t   database_sequencest   database_letters(   R   R/   R   Rd   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR,     s    c         C   s4   |  j  j j   |  j  _ |  j  j j   |  j  _ d  S(   N(   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/NCBIStandalone.pyR.   (  s    (   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/NCBIStandalone.pyR      s   					t   _DescriptionConsumerc           B   sb   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   c         C   sC   g  |  _  g  |  _ g  |  _ d |  _ d  |  _ d  |  _ d |  _ d  S(   Ni    (   t   _descriptionst   _model_sequencest   _nonmodel_sequencest
   _convergedR4   t   _typet	   _roundnumt   _DescriptionConsumer__has_n(   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/NCBIStandalone.pyR>   .  s    						c         C   s>   | j  d  r: | j   } | d d k r: d |  _ q: n  d  S(   Ns   Sequences producingit   Ni   (   R'   R   R   (   R   R/   t   cols(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR@   8  s    c         C   sg   |  j  |  } |  j d k r1 |  j j |  n2 |  j d k rS |  j j |  n |  j j |  d  S(   Nt   modelt   nonmodel(   t   _parseR   R   t   appendR   R   (   R   R/   t   dh(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyRE   >  s    c         C   s   d |  _  d  S(   NR   (   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/NCBIStandalone.pyRD   G  s    c         C   s   d |  _  d  S(   NR   (   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/NCBIStandalone.pyRF   J  s    c         C   s   d |  _  d  S(   Ni   (   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/NCBIStandalone.pyRG   M  s    c         C   s   d  S(   N(    (   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/NCBIStandalone.pyRB   P  s    c         C   s?   | j  d  s" t d |   n  t | d j    |  _ d  S(   Ns   Results from rounds%   I didn't understand the round line
%si   (   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/NCBIStandalone.pyR?   S  s    c         C   s   d  S(   N(    (   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/NCBIStandalone.pyRC   X  s    c         C   s  | } t  j   } | j   } t |  d k  rC t d |   n  |  j r | j | d  } | j | d d |  } | j | d d |  } n, | j | d  } | j | d d |  } |  j r| |  j   | d | d | d f \ | _ | _	 | _
 | _ n< | |  j   | d | d d f \ | _ | _	 | _
 | _ t | j  | _ t | j	  | _	 t | j
  | _
 | S(   Ni   s/   Line does not appear to contain description:
%siii    ii   (   R   t   DescriptionR   t   lenR-   R   t   rfindR   RQ   RY   t   et   num_alignmentsR   t   _safe_float(   R   t   description_lineR/   R   R   t   i(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR   [  s&    			C<(   R   R   R>   R@   RE   RD   RF   RG   RB   R?   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/NCBIStandalone.pyR   -  s   	
									t   _AlignmentConsumerc           B   s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C   s"   t  j   |  _ t  j   |  _ d  S(   N(   R   t	   Alignmentt
   _alignmentt   MultipleAlignmentt   _multiple_alignment(   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/NCBIStandalone.pyRM     s    c         C   s&   d |  j  j | j   f |  j  _ d  S(   Ns   %s%s(   R   RQ   RS   (   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/NCBIStandalone.pyRQ     s    c         C   se   | j  d d  j d  } t |  d k s9 t d   | d |  j _ t |  j j  |  j _ d  S(   Nt    R   t   =i   s   Unrecognised format length linei   (   t   replaceR   R   R*   R   RT   R   (   R   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/NCBIStandalone.pyRT     s    c         C   s  | j  d  s | j  d  r y | j   \ } } } } Wn! t k
 r] t d |   n X| j | t |   |  _ | j | |  j t |   |  _ |  j d |  _ |  j |  j d |  _ | j	 |  |  j d |  _
 n  | |  j  } | j   } | |  j |  j |  j !} | j   } | r6t |  } n  | |  j |  j
 j   } | ret |  } n  | |  j |  j |  j
 !j   } t |  |  j
 k  r| d |  j
 t |  } n  |  j j } | j | | | | f  d  S(   NR=   t	   blast_tmps   I do not understand the line
%si   R   (   R'   R   R-   t   indexR   t   _start_indext
   _seq_indext   _name_lengtht   _start_lengthR   t   _seq_lengthR   R   R   t	   alignmentR   (   R   R/   t   nameR   t   seqR   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/NCBIStandalone.pyRc     s2    	 
 c         C   s^   |  j  r$ |  j  j j   |  j  _ n  y" |  ` |  ` |  ` |  ` |  ` Wn t k
 rY n Xd  S(   N(	   R   RQ   R   R   R   R   R   R   t   AttributeError(   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/NCBIStandalone.pyRP     s    	
(   R   R   RM   RQ   RT   Rc   RP   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR   |  s
   				mt   _HSPConsumerc           B   sw   e  Z d    Z d   Z d   Z d   Z d   Z e j d  Z	 d   Z
 d   Z e j d  Z d	   Z d
   Z RS(   c         C   s   t  j   |  _ d  S(   N(   R   t   HSPt   _hsp(   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/NCBIStandalone.pyRU      s    c         C   s   t  d | d |  \ |  j _ |  j _ t |  j j  |  j _ t |  j j  |  j _ t  d | d |  \ } } | r t |  |  j _ n d |  j _ t |  |  j _ d  S(   Ns'   Score =\s*([0-9.e+]+) bits \(([0-9]+)\)s%   I could not find the score in line
%ss$   Expect\(?(\d*)\)? = +([0-9.e\-|\+]+)s&   I could not find the expect in line
%si   (   R   R   t   bitsRY   R   R   R   t   expect(   R   R/   Rq   t   y(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyRY   #  s    c         C   s0  t  d | d |  \ } } t |  t |  f |  j _ t |  |  j _ | j d  d k r t  d | d |  \ } } t |  t |  f |  j _ |  j j t |  k s t  n  | j d  d k r,t  d | d	 |  \ } } t |  t |  f |  j _ |  j j t |  k s,t  n  d  S(
   Ns   Identities = (\d+)\/(\d+)s*   I could not find the identities in line
%st	   Positivesis   Positives = (\d+)\/(\d+)s)   I could not find the positives in line
%st   Gapss   Gaps = (\d+)\/(\d+)s$   I could not find the gaps in line
%s(	   R   R   R   RZ   t   align_lengthR5   t	   positivesR*   t   gaps(   R   R/   Rq   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/NCBIStandalone.pyRZ   3  s"    !c         C   s    t  d | d |  |  j _ d  S(   Ns   Strand = (\w+) / (\w+)s&   I could not find the strand in line
%s(   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/NCBIStandalone.pyR[   I  s    c         C   sT   | j  d  d k r4 t d | d |  |  j _ n t d | d |  |  j _ d  S(   Nt   /is!   Frame = ([-+][123]) / ([-+][123])s%   I could not find the frame in line
%ss   Frame = ([-+][123])(   R5   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/NCBIStandalone.pyR\   N  s    s   Query(:?) \s*(\d+)\s*(.+) (\d+)c         C   s   |  j  j |  } | d  k r1 t d |   n  | j   \ } } } } |  j j | |  j _ |  j j d  k r t |  |  j _ n  t |  |  j _	 | j
 d  |  _ t |  |  _ d  S(   Ns%   I could not find the query in line
%si   (   t	   _query_reR3   R4   R-   t   groupsR   R_   t   query_startR   t	   query_endR   t   _query_start_indexR   t
   _query_len(   R   R/   t   mt   colonR   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/NCBIStandalone.pyR_   a  s    c         C   s   | |  j  j   } t |  |  j k  rF | d |  j t |  } n( t |  |  j k  rn t d |   n  |  j j | |  j _ d  S(   NR   s)   Match is longer than the query in line
%s(   R   R   R   R   R-   R   t   match(   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/NCBIStandalone.pyR`   u  s    s   Sbjct(:?) \s*(\d+)\s*(.+) (\d+)c         C   s   |  j  j |  } | d  k r1 t d |   n  | j   \ } } } } | j   se d |  j } n  |  j j | |  j _ |  j j	 d  k r t
 |  |  j _	 n  t
 |  |  j _ t |  |  j k r t d |   n  |  ` |  ` d  S(   Ns%   I could not find the sbjct in line
%sR   s7   QUERY and SBJCT sequence lengths don't match in line
%s(   t	   _sbjct_reR3   R4   R-   R   R)   R   R   Ra   t   sbjct_startR   t	   sbjct_endR   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/NCBIStandalone.pyRa     s     c         C   s   d  S(   N(    (   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/NCBIStandalone.pyRX     s    (   R   R   RU   RY   RZ   R[   R\   R2   RA   R   R_   R`   R   Ra   RX   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR     s   								t   _DatabaseReportConsumerc           B   sY   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   c         C   s   t  j   |  _ d  S(   N(   R   t   DatabaseReportt   _dr(   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/NCBIStandalone.pyRg     s    c         C   st   t  j d |  } | r7 |  j j j | j d   n9 |  j j rp d |  j j d | j   f |  j j d <n  d  S(   Ns   Database: (.+)$i   s   %s%si(   R2   R3   R   t   database_nameR   t   groupR)   (   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/NCBIStandalone.pyRh     s    c         C   s'   |  j  j j t d | d |   d  S(   Ns   Posted date:\s*(.+)$s+   I could not find the posted date in line
%s(   R   Rj   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/NCBIStandalone.pyRj     s    c      	   C   sI   t  | d	 d d d i d d 6d d 6\ } |  j j j t |   d  S(
   Nit   ncolsi   t   expectedRd   i   s	   database:i   (   i(   t	   _get_colsR   Rk   R   R   (   R   R/   Rd   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyRk     s    )c      	   C   sI   t  | d	 d d d i d d 6d d 6\ } |  j j j t |   d  S(
   NiR   i   R   R   i   s	   database:i   (   i(   R   R   Rl   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/NCBIStandalone.pyRl     s    )c         C   s%   | j    } t t |  |  j _ d  S(   N(   R   t   mapR   R   Rm   (   R   R/   Rq   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyRm     s    c         C   s   d |  j  _ d  S(   Ni   (   R   Rn   (   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/NCBIStandalone.pyRn     s    c         C   s%   | j    } t t |  |  j _ d  S(   N(   R   R   R   R   Ro   (   R   R/   Rq   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyRo     s    c         C   s   d  S(   N(    (   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/NCBIStandalone.pyRi     s    (   R   R   Rg   Rh   Rj   Rk   Rl   Rm   Rn   Ro   Ri   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR     s   									t   _ParametersConsumerc           B   s  e  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 RS(   c         C   s   t  j   |  _ d  S(   N(   R   t
   Parameterst   _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/NCBIStandalone.pyR}     s    c         C   s   | d j    |  j _ d  S(   Ni   (   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/NCBIStandalone.pyR~     s    c      	   C   sB   t  | d
 d d d i d d 6d d	 6} t t |  |  j _ d  S(   Ni   i   R   i   R   s
   Existence:i   s
   Extension:i   (   i   i   (   R   R   R   R   R   (   R   R/   Rq   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR     s    &c      	   C   s   | j  d  d k rO t | d
 d d d i d d 6\ } t |  |  j _ n7 t | d d d	 d i d d 6\ } t |  |  j _ d  S(   Ns   1st passiiR   i   R   t   Hitsi   i   (   i(   i(   R5   R   R   R   R   (   R   R/   Rq   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR     s
    %%c      	   C   s   | j  d  d k rO t | d
 d d d i d d 6\ } t |  |  j _ n7 t | d d d	 d i d d 6\ } t |  |  j _ d  S(   Ns   1st passiiR   i	   R   s
   Sequences:i   i   (   i(   i(   R5   R   R   R   R   (   R   R/   Rq   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR     s
    %%c      	   C   s   | j  d  d k rO t | d
 d d d i d d 6\ } t |  |  j _ n7 t | d d d	 d i d d 6\ } t |  |  j _ d  S(   Ns   1st passiiR   i	   R   s   extensions:i   i   (   i(   i(   R5   R   R   R   R   (   R   R/   Rq   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR     s
    %%c      	   C   s   | j  d  d k rO t | d
 d d d i d d 6\ } t |  |  j _ n7 t | d d d	 d i d d 6\ } t |  |  j _ d  S(   Ns   1st passiiR   i
   R   s   extensions:i   i   (   i(   i(   R5   R   R   R   R   (   R   R/   Rq   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR     s
    %%c      	   C   sG   t  | d d d d i d d 6\ |  j _ t |  j j  |  j _ d  S(   NiR   i   R   R   i   (   i(   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/NCBIStandalone.pyR     s    (c      	   C   sN   t  | d	 d d d i d d 6d d 6\ |  j _ t |  j j  |  j _ d  S(
   NiR   i	   R   t   betteri   s   gapping:i   (   i(   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/NCBIStandalone.pyR     s    /c      	   C   sN   t  | d	 d d d i d d 6d d 6\ |  j _ t |  j j  |  j _ d  S(
   NiR   i	   R   Rn   i   t   prelimi   (   i(   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/NCBIStandalone.pyR     s    /c      	   C   sN   t  | d	 d d d i d d 6d d 6\ |  j _ t |  j j  |  j _ d  S(
   NiR   i
   R   t	   attemptedi   R   i   (   i(   R   R   t   hsps_prelim_gapped_attemptedR   (   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/NCBIStandalone.pyR    s    /c      	   C   sG   t  | d d d d i d d 6\ |  j _ t |  j j  |  j _ d  S(   NiR   i   R   Rn   i   (   i(   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/NCBIStandalone.pyR     s    (c      	   C   sT   t  | j   d	 d d d i d d 6d d 6\ |  j _ t |  j j  |  j _ d  S(
   NiR   i   R   RT   i    s   query:i   (   i(   R   t   lowerR   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/NCBIStandalone.pyR     s    5c      	   C   sT   t  | j   d	 d d d i d d 6d d 6\ |  j _ t |  j j  |  j _ d  S(
   NiR   i   R   RT   i    s	   database:i   (   i(   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/NCBIStandalone.pyR     s    5c      	   C   sN   t  | d	 d d d i d d 6d d 6\ |  j _ t |  j j  |  j _ d  S(
   NiR   i   R   R   i   s   length:i   (   i(   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/NCBIStandalone.pyR     s    /c      	   C   sN   t  | d	 d d d i d d 6d d 6\ |  j _ t |  j j  |  j _ d  S(
   NiR   i   R   RT   i   s   query:i   (   i(   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/NCBIStandalone.pyR      s    /c      	   C   sT   t  | j   d	 d d d i d d 6d d 6\ |  j _ t |  j j  |  j _ d  S(
   NiR   i   R   RT   i   s	   database:i   (   i(   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/NCBIStandalone.pyR   &  s    5c      	   C   sG   t  | d d d d i d d 6\ |  j _ t |  j j  |  j _ d  S(   NiR   i   R   R3   i   (   i(   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/NCBIStandalone.pyR   ,  s    (c      	   C   sN   t  | d	 d d d i d d 6d d 6\ |  j _ t |  j j  |  j _ d  S(
   NiR   i   R   R3   i   s   used:i   (   i(   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/NCBIStandalone.pyR   2  s    /c      	   C   s3   t  | d
 d d d i d d 6d d	 6|  j _ d  S(   Ni   i   R   i   R   Rt   i    t   decayi   (   i   i   (   R   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/NCBIStandalone.pyRt   8  s    c      	   C   s   | d  d k r> t  | d d d d i d d 6\ |  j _ n\ | d  d k r t  | d d d
 d i d d 6d d 6d d 6\ |  j _ n t d |   t |  j j  |  j _ d  S(   Ni   s   T:i   R   R   i    i   s   Neighboring words threshold:i   i   t   Neighboringt   wordss
   threshold:s   Unrecognised threshold line:
%s(   i   (   i   (   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/NCBIStandalone.pyR   <  s    +9c      	   C   s   | d  d k r> t  | d d d d i d d 6\ |  j _ n\ | d  d k r t  | d d d
 d i d d 6d d 6d d 6\ |  j _ n t d |   t |  j j  |  j _ d  S(   Ni   s   A:i   R   R   i    i   s   Window for multiple hits:i   i   t   Windowt   multiples   hits:i   s!   Unrecognised window size line:
%s(   i   (   i   (   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/NCBIStandalone.pyR   H  s    +9c         C   s>   t  d | d |  \ } } t |  t |  f |  j _ d  S(   Ns    X1: (\d+) \(\s*([0-9,.]+) bits\)s'   I could not find the dropoff in line
%s(   R   R   R   R   R   (   R   R/   RY   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/NCBIStandalone.pyR   S  s    c         C   s>   t  d | d |  \ } } t |  t |  f |  j _ d  S(   Ns    X2: (\d+) \(\s*([0-9,.]+) bits\)s+   I could not find the gap dropoff in line
%s(   R   R   R   R   R   (   R   R/   RY   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/NCBIStandalone.pyR   Y  s    c         C   s>   t  d | d |  \ } } t |  t |  f |  j _ d  S(   Ns    X3: (\d+) \(\s*([0-9,.]+) bits\)s1   I could not find the gap dropoff final in line
%s(   R   R   R   R   R   (   R   R/   RY   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/NCBIStandalone.pyR   _  s    c         C   s>   t  d | d |  \ } } t |  t |  f |  j _ d  S(   Ns    S1: (\d+) \(\s*([0-9,.]+) bits\)s+   I could not find the gap trigger in line
%s(   R   R   R   R   R   (   R   R/   RY   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/NCBIStandalone.pyR   e  s    c         C   s>   t  d | d |  \ } } t |  t |  f |  j _ d  S(   Ns    S2: (\d+) \(\s*([0-9,.]+) bits\)s,   I could not find the blast cutoff in line
%s(   R   R   R   R   R   (   R   R/   RY   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/NCBIStandalone.pyR   k  s    c         C   s   d  S(   N(    (   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/NCBIStandalone.pyR   q  s    (   R   R   R}   R~   R   R   R   R   R   R   R   R   R  R   R   R   R   R   R   R   R   Rt   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/NCBIStandalone.pyR     s8   																											R   c           B   sY   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   c         C   s   d  |  _ d  S(   N(   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/NCBIStandalone.pyR     s    c         C   s   t  d   d  S(   Ns+   This consumer doesn't handle PSI-BLAST data(   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/NCBIStandalone.pyR?     s    c         C   s    t  j   |  _ t j |   d  S(   N(   R   t   BlastR   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/NCBIStandalone.pyR     s    c         C   s*   t  j |   |  j j j |  j j  d  S(   N(   R   R.   R   t   __dict__t   updateR   (   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/NCBIStandalone.pyR.     s    c         C   s   |  j  |  j _ d  S(   N(   R   R   t   descriptions(   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/NCBIStandalone.pyRC     s    c         C   sT   t  j |   |  j j r2 |  j j j |  j  n  |  j j rP |  j |  j _	 n  d  S(   N(
   R   RP   R   t   hspsR   t
   alignmentsR   R   R   t   multiple_alignment(   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/NCBIStandalone.pyRP     s
    c         C   sK   t  j |   y |  j j j |  j  Wn t k
 rF t d   n Xd  S(   Ns    Found an HSP before an alignment(   R   RX   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/NCBIStandalone.pyRX     s
    c         C   s*   t  j |   |  j j j |  j j  d  S(   N(   R   Ri   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/NCBIStandalone.pyRi     s    c         C   s*   t  j |   |  j j j |  j j  d  S(   N(   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/NCBIStandalone.pyR     s    (   R   R   R   R?   R   R.   RC   RP   RX   Ri   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/NCBIStandalone.pyR   u  s   								R   c           B   sY   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   c         C   s   d  |  _ d  S(   N(   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/NCBIStandalone.pyR     s    c         C   s    t  j   |  _ t j |   d  S(   N(   R   t   PSIBlastR   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/NCBIStandalone.pyR     s    c         C   s*   t  j |   |  j j j |  j j  d  S(   N(   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/NCBIStandalone.pyR.     s    c         C   s6   t  j   |  _ |  j j j |  j  t j |   d  S(   N(   R   t   Roundt   _roundR   t   roundsR   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/NCBIStandalone.pyR>     s    c         C   s   t  j |   |  j |  j _ |  j r> |  j j j |  j  n  |  j j j |  j	  |  j j j |  j
  |  j r d |  j _ n  d  S(   Ni   (   R   RC   R   R  t   numberR   t   new_seqst   extendt   reused_seqsR   R   R   R   RG   (   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/NCBIStandalone.pyRC     s    		c         C   sQ   t  j |   |  j j r2 |  j j j |  j  n  |  j rM |  j |  j _ n  d  S(   N(	   R   RP   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/NCBIStandalone.pyRP     s
    	c         C   sK   t  j |   y |  j j j |  j  Wn t k
 rF t d   n Xd  S(   Ns    Found an HSP before an alignment(   R   RX   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/NCBIStandalone.pyRX     s
    c         C   s*   t  j |   |  j j j |  j j  d  S(   N(   R   Ri   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/NCBIStandalone.pyRi     s    c         C   s*   t  j |   |  j j j |  j j  d  S(   N(   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/NCBIStandalone.pyR     s    (   R   R   R   R   R.   R>   RC   RP   RX   Ri   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/NCBIStandalone.pyR     s   					
			t   Iteratorc           B   s,   e  Z d  Z d d  Z d   Z d   Z RS(   s   Iterates over a file of multiple BLAST results.

    Methods:
    next   Return the next record from the stream, or None.

    c         C   sT   y | j  Wn' t k
 r4 t d t |    n Xt j |  |  _ | |  _ d S(   s  __init__(self, handle, parser=None)

        Create a new iterator.  handle is a file-like object.  parser
        is an optional Parser object to change the results into another form.
        If set to None, then the raw contents of the file will be returned.

        s4   I expected a file handle or file-like object, got %sN(   R%   R   R-   t   typeR    R   t   _uhandlet   _parser(   R   R   t   parser(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR     s    c         C   s   g  } xt |  j  j   } | s" Pn  | rl | j d  sX | j d d  sX | j d  rl |  j  j |  Pn  | j |  q	 W| s d Sd j |  } |  j d k	 r |  j j t	 j
 |   S| S(   s}   next(self) -> object

        Return the next Blast record from the file.  If no more records,
        return None.

        R
   i   s   <?xml R   N(   R  R%   R'   Rb   R   R4   t   joinR  R   R    t   StringHandle(   R   t   linesR/   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/NCBIStandalone.pyt   next  s"    c         C   s   t  |  j d   S(   N(   t   iterR   R4   (   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/NCBIStandalone.pyt   __iter__  s    N(   R   R   R   R4   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/NCBIStandalone.pyR    s   	t   7c   	      K   s  t  |  i  d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d  6d! d" 6d# d$ 6d% d& 6d' d( 6d) d* 6d+ d, 6d- d. 6d/ d0 6d1 d2 6d3 d4 6d5 d6 6d7 d8 6d9 d: 6d; d< 6d= d> 6d? d@ 6} g  } | j | d$ | g  | j | d& | g  | j | d( t |  g  | j | d: t |  g  x5 | j   D]' } | j | | t | |  g  qkWt |  |  S(A   s[
  Execute and retrieve data from standalone BLASTPALL as handles.
    
    Execute and retrieve data from blastall.  blastcmd is the command
    used to launch the 'blastall' executable.  program is the blast program
    to use, e.g. 'blastp', 'blastn', etc.  database is the path to the database
    to search against.  infile is the path to the file containing
    the sequence to search with.

    The return values are two handles, for standard output and standard error.

    You may pass more parameters to **keywds to change the behavior of
    the search.  Otherwise, optional values will be chosen by blastall.
    The Blast output is by default in XML format. Use the align_view keyword
    for output in a different format.
    
        Scoring
    matrix              Matrix to use.
    gap_open            Gap open penalty.
    gap_extend          Gap extension penalty.
    nuc_match           Nucleotide match reward.  (BLASTN)
    nuc_mismatch        Nucleotide mismatch penalty.  (BLASTN)
    query_genetic_code  Genetic code for Query.
    db_genetic_code     Genetic code for database.  (TBLAST[NX])

        Algorithm
    gapped              Whether to do a gapped alignment. T/F (not for TBLASTX)
    expectation         Expectation value cutoff.
    wordsize            Word size.
    strands             Query strands to search against database.([T]BLAST[NX])
    keep_hits           Number of best hits from a region to keep.
    xdrop               Dropoff value (bits) for gapped alignments.
    hit_extend          Threshold for extending hits.
    region_length       Length of region used to judge hits.
    db_length           Effective database length.
    search_length       Effective length of search space.

        Processing
    filter              Filter query sequence for low complexity (with SEG)?  T/F
    believe_query       Believe the query defline.  T/F
    restrict_gi         Restrict search to these GI's.
    nprocessors         Number of processors to use.
    oldengine           Force use of old engine T/F

        Formatting
    html                Produce HTML output?  T/F
    descriptions        Number of one-line descriptions.
    alignments          Number of alignments.
    align_view          Alignment view.  Integer 0-11,
                        passed as a string or integer.
    show_gi             Show GI's in deflines?  T/F
    seqalign_file       seqalign file to output.
    outfile             Output file for report.  Filename to write to, if
                        ommitted standard output is used (which you can access
                        from the returned handles).
    s   -MR~   s   -Gt   gap_opens   -Et
   gap_extends   -rt	   nuc_matchs   -qt   nuc_mismatchs   -Qt   query_genetic_codes   -Dt   db_genetic_codes   -gRn   s   -et   expectations   -Wt   wordsizes   -St   strandss   -Kt	   keep_hitss   -Xt   xdrops   -ft
   hit_extends   -Lt   region_lengths   -zt	   db_lengths   -Yt   search_lengths   -pt   programs   -dRh   s   -it   infiles   -Ft   filters   -Jt   believe_querys   -lt   restrict_gis   -at   nprocessorss   -Vt	   oldengines   -Tt   htmls   -vR  s   -bR  s   -mt
   align_views   -It   show_gis   -Ot   seqalign_files   -ot   outfile(   t   _security_check_parametersR  t   _escape_filenameRp   t   keyst   _invoke_blast(	   t   blastcmdR3  Rh   R4  R;  t   keywdst	   att2paramt   paramst   attr(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyt   blastall  sT    9

%c         K   s  t  |  i( d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d  6d! d" 6d d# 6d$ d% 6d& d' 6d( d) 6d* d+ 6d, d- 6d. d/ 6d0 d1 6d2 d3 6d4 d5 6d6 d7 6d8 d9 6d: d; 6d< d= 6d> d? 6d@ dA 6dB dC 6dD dE 6dF dG 6dH dI 6dJ dK 6dL dM 6dN dO 6} g  } | j | d/ | g  | j | d1 t |  g  | j | d? t |  g  x5 | j   D]' } | j | | t | |  g  qWt |  |  S(P   sl  Execute and retrieve data from standalone BLASTPGP as handles.
    
    Execute and retrieve data from blastpgp.  blastcmd is the command
    used to launch the 'blastpgp' executable.  database is the path to the
    database to search against.  infile is the path to the file containing
    the sequence to search with.

    The return values are two handles, for standard output and standard error.

    You may pass more parameters to **keywds to change the behavior of
    the search.  Otherwise, optional values will be chosen by blastpgp.
    The Blast output is by default in XML format. Use the align_view keyword
    for output in a different format.

        Scoring
    matrix              Matrix to use.
    gap_open            Gap open penalty.
    gap_extend          Gap extension penalty.
    window_size         Multiple hits window size.
    npasses             Number of passes.
    passes              Hits/passes.  Integer 0-2.

        Algorithm
    gapped              Whether to do a gapped alignment.  T/F
    expectation         Expectation value cutoff.
    wordsize            Word size.
    keep_hits           Number of beset hits from a region to keep.
    xdrop               Dropoff value (bits) for gapped alignments.
    hit_extend          Threshold for extending hits.
    region_length       Length of region used to judge hits.
    db_length           Effective database length.
    search_length       Effective length of search space.
    nbits_gapping       Number of bits to trigger gapping.
    pseudocounts        Pseudocounts constants for multiple passes.
    xdrop_final         X dropoff for final gapped alignment.
    xdrop_extension     Dropoff for blast extensions.
    model_threshold     E-value threshold to include in multipass model.
    required_start      Start of required region in query.
    required_end        End of required region in query.

        Processing
    XXX should document default values
    program             The blast program to use. (PHI-BLAST)
    filter              Filter query sequence  for low complexity (with SEG)?  T/F
    believe_query       Believe the query defline?  T/F
    nprocessors         Number of processors to use.

        Formatting
    html                Produce HTML output?  T/F
    descriptions        Number of one-line descriptions.
    alignments          Number of alignments.
    align_view          Alignment view.  Integer 0-11,
                        passed as a string or integer.
    show_gi             Show GI's in deflines?  T/F
    seqalign_file       seqalign file to output.
    align_outfile       Output file for alignment.
    checkpoint_outfile  Output file for PSI-BLAST checkpointing.
    restart_infile      Input file for PSI-BLAST restart.
    hit_infile          Hit file for PHI-BLAST.
    matrix_outfile      Output file for PSI-BLAST matrix in ASCII.
    align_outfile       Output file for alignment.  Filename to write to, if
                        ommitted standard output is used (which you can access
                        from the returned handles).

    align_infile        Input alignment file for PSI-BLAST restart.
    
    s   -MR~   s   -GR$  s   -ER%  s   -AR   s   -jt   npassess   -Pt   passess   -gRn   s   -eR*  s   -WR+  s   -KR-  s   -XR.  s   -fR/  s   -LR0  s   -ZR1  s   -YR2  s   -Nt   nbits_gappings   -ct   pseudocountst   xdrop_finals   -yt   xdrop_extensions   -ht   model_thresholds   -St   required_starts   -Ht   required_ends   -pR3  s   -dRh   s   -iR4  s   -FR5  s   -JR6  s   -aR8  s   -TR:  s   -vR  s   -bR  s   -mR;  s   -IR<  s   -OR=  s   -ot   align_outfiles   -Ct   checkpoint_outfiles   -Rt   restart_infiles   -kt
   hit_infiles   -Qt   matrix_outfiles   -Bt   align_infile(   R?  R  R@  Rp   RA  RB  (   RC  Rh   R4  R;  RD  RE  RF  RG  (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyt   blastpgp  sb    E

%c         K   s[  t  |  i d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d  6d! d" 6d# d$ 6d% d& 6d' d( 6d) d* 6d+ d, 6d- d. 6d/ d0 6d1 d2 6} g  } | j | d | g  | j | d t |  g  | j | d, t |  g  x5 | j   D]' } | j | | t | |  g  q#Wt |  |  S(3   s_  Execute and retrieve data from standalone RPS-BLAST as handles.
    
    Execute and retrieve data from standalone RPS-BLAST.  blastcmd is the
    command used to launch the 'rpsblast' executable.  database is the path
    to the database to search against.  infile is the path to the file
    containing the sequence to search with.

    The return values are two handles, for standard output and standard error.

    You may pass more parameters to **keywds to change the behavior of
    the search.  Otherwise, optional values will be chosen by rpsblast.

    Please note that this function will give XML output by default, by
    setting align_view to seven (i.e. command line option -m 7).
    You should use the NCBIXML.parse() function to read the resulting output.
    This is because NCBIStandalone.BlastParser() does not understand the
    plain text output format from rpsblast.

    WARNING - The following text and associated parameter handling has not
    received extensive testing.  Please report any errors we might have made...

        Algorithm/Scoring
    gapped              Whether to do a gapped alignment.  T/F
    multihit            0 for multiple hit (default), 1 for single hit
    expectation         Expectation value cutoff.
    range_restriction   Range restriction on query sequence (Format: start,stop) blastp only
                        0 in 'start' refers to the beginning of the sequence
                        0 in 'stop' refers to the end of the sequence
                        Default = 0,0
    xdrop               Dropoff value (bits) for gapped alignments.
    xdrop_final         X dropoff for final gapped alignment (in bits).
    xdrop_extension     Dropoff for blast extensions (in bits).
    search_length       Effective length of search space.
    nbits_gapping       Number of bits to trigger gapping.
    protein             Query sequence is protein.  T/F
    db_length           Effective database length.

        Processing
    filter              Filter query sequence for low complexity?  T/F
    case_filter         Use lower case filtering of FASTA sequence T/F, default F
    believe_query       Believe the query defline.  T/F
    nprocessors         Number of processors to use.
    logfile             Name of log file to use, default rpsblast.log

        Formatting
    html                Produce HTML output?  T/F
    descriptions        Number of one-line descriptions.
    alignments          Number of alignments.
    align_view          Alignment view.  Integer 0-11,
                        passed as a string or integer.
    show_gi             Show GI's in deflines?  T/F
    seqalign_file       seqalign file to output.
    align_outfile       Output file for alignment.  Filename to write to, if
                        ommitted standard output is used (which you can access
                        from the returned handles).
    s   -Pt   multihits   -gRn   s   -eR*  s   -Lt   range_restrictions   -XR.  s   -ZRM  s   -yRN  s   -YR2  s   -NRK  s   -pt   proteins   -zR1  s   -dRh   s   -iR4  s   -FR5  s   -Ut   case_filters   -JR6  s   -aR8  s   -lt   logfiles   -TR:  s   -vR  s   -bR  s   -mR;  s   -IR<  s   -OR=  s   -oRR  (   R?  R  R@  Rp   RA  RB  (   RC  Rh   R4  R;  RD  RE  RF  RG  (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyt   rpsblast  sD    :

%c         C   s1   t  j |  |  } | s' t |   n  | j   S(   N(   R2   R3   R-   R   (   t   regexR/   t	   error_msgR   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR   m  s    c         C   s   |  j    } | d  k	 rL t |  | k rL t d | t |  |  f   n  xH | j   D]: } | | | | k rY t d | | | |  f   qY qY Wg  } x | D] } | j | |  q Wt |  S(   Ns)   I expected %d columns (got %d) in line
%ss'   I expected '%s' in column %d in line
%s(   R   R4   R   R-   RA  R   t   tuple(   R/   t   cols_to_getR   R   R   t   kt   resultsR   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR   s  s    c         C   sf   y t  |   SWn# t k
 r3 |  j d d  }  n Xy t  |   SWn t k
 rU n Xt t |    S(   Nt   ,R   (   t   intR-   R   t   longt   float(   Rp   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR     s    c         C   sa   |  r# |  d d k r# d |  }  n  y t  |   SWn# t k
 rV |  j d d  }  n Xt  |   S(   Ni    t   ER   t   1Re  R   (   Ri  R   (   Rh  R-   R   (   Rp   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR     s    c         C   s>   d |  k r |  S|  j  d  r2 |  j d  r2 |  Sd |  Sd S(   s'   Escape filenames with spaces (PRIVATE).R   t   "s   "%s"N(   R'   R   (   t   filename(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR@    s
    c   	      C   s   t  j j |   s% t d |    n  d j t |   g |  } yr d d l } d d l } | j | d | j	 d | j	 d | j	 d | j
 d	 k } | j j   | j | j f SWn: t k
 r t  j |  \ } } } | j   | | f SXd S(
   s   Start BLAST and returns handles for stdout and stderr (PRIVATE).

    Tries to deal with spaces in the BLAST executable path.
    s%   BLAST executable does not exist at %sR   iNt   stdint   stdoutt   stderrt   shellt   win32(   t   ost   patht   existsR-   R  R@  t
   subprocesst   syst   Popent   PIPEt   platformRm  t   closeRn  Ro  t   ImportErrort   popen3(	   t	   blast_cmdRF  t
   cmd_stringRu  Rv  t   blast_processt   write_handlet   result_handlet   error_handle(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyRB    s     			
c         C   sl   xe |  j    D]W \ } } t |  } x< d d d d d g D]% } | | k r; t d |   q; q; Wq Wd S(   s8  Look for any attempt to insert a command into a parameter.

    e.g. blastall(..., matrix='IDENTITY -F 0; rm -rf /etc/passwd')

    Looks for ";" or "&&" in the strings (Unix and Windows syntax
    for appending a command line), or ">", "<" or "|" (redirection)
    and if any are found raises an exception.
    t   ;s   &&R<   t   <t   |s$   Rejecting suspicious argument for %sN(   t	   iteritemsRp   R-   (   t
   param_dictt   keyt   valuet	   str_valuet   bad_str(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR?    s
    	t   _BlastErrorConsumerc           B   s   e  Z d    Z d   Z RS(   c         C   s   t  j |   d  S(   N(   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/NCBIStandalone.pyR     s    c         C   sP   | j  d  d k r$ t d   n  t t d t j |  d   } | |  d  S(   Ns   Query must be at least wordsizeiR   (   R5   R   t   getattrR   t   __getattr__(   R   R/   t   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/NCBIStandalone.pyR     s
    	(   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/NCBIStandalone.pyR    s   	t   BlastErrorParserc           B   s,   e  Z d  Z d d  Z d   Z d   Z RS(   s  Attempt to catch and diagnose BLAST errors while parsing.

    This utilizes the BlastParser module but adds an additional layer
    of complexity on top of it by attempting to diagnose ValueErrors
    that may actually indicate problems during BLAST parsing.

    Current BLAST problems this detects are:
    o LowQualityBlastError - When BLASTing really low quality sequences
    (ie. some GenBank entries which are just short streches of a single
    nucleotide), BLAST will report an error with the sequence and be
    unable to search with this. This will lead to a badly formatted
    BLAST report that the parsers choke on. The parser will convert the
    ValueError to a LowQualityBlastError and attempt to provide useful
    information.
    
    c         C   s%   | |  _  t   |  _ t   |  _ d S(   s]  Initialize a parser that tries to catch BlastErrors.

        Arguments:
        o bad_report_handle - An optional argument specifying a handle
        where bad reports should be sent. This would allow you to save
        all of the bad reports to a file, for instance. If no handle
        is specified, the bad reports will not be saved.
        N(   t   _bad_report_handleR   R   R  R   (   R   t   bad_report_handle(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR     s    		c         C   s   | j    } y# |  j j t j |  |  j  WnQ t k
 r } |  j r] |  j j |  n  |  j	 t j |  |  j j
    n X|  j j
 S(   s7   Parse a handle, attempting to diagnose errors.
        (   t   readR   R   R    R  R   R-   R  t   writet   _diagnose_errorR   (   R   R   Rd  t   msg(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR     s    #	c         C   sM   | j    } x: | rH | j d  r9 t d | j   n  | j    } q Wd S(   s   Attempt to diagnose an error in the passed handle.

        Arguments:
        o handle - The handle potentially containing the error
        o data_record - The data record partially created by the consumer.
        t   Searchingdones    Blast failure occured on query: N(   R%   R'   R   R_   (   R   R   t   data_recordR/   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Blast/NCBIStandalone.pyR  0  s    	N(   R   R   R   R4   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/NCBIStandalone.pyR    s   	(&   R   Rr  R2   t   BioR    t   Bio.ParserSupportt	   Bio.BlastR   t	   ExceptionR   R   R   t   AbstractParserR   R   R   R   R   R   R   R   t   AbstractConsumerR   R   R  RH  RX  R^  R   R4   R   R   R   R@  RB  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/NCBIStandalone.pyt   <module>#   sZ   
  -O~+327le					 	