
62Pc           @   sh  d  Z  d. Z d d l Z d d l Z y d d l Z Wn e k
 rM d Z n Xd   Z d   Z	 d   Z
 d   Z d   Z d   Z d   Z d d d   Z d!   Z d	 e f d"     YZ d#   Z d e f d$     YZ d%   Z d a d&   Z d e f d'     YZ d d(  Z d e f d)     YZ d e f d*     YZ d d+  Z d d,  Z d d-  Z  d S(/   s9   Extra utilities and core classes not in standard python.
t   isblankt   isfloatt   isintt   fcmpt   remove_whitespacet   invert_dictt   updatet   stdreprt   Tokent   Structt	   Reiteratet
   deoptparset   crc32t   crc64t	   FileIndext   find_commandt   ArgumentErrort
   frozendictt   group_countt   resource_stringt   resource_streamt   resource_filenameiNc         C   s   |  d k r t  S|  j   S(   s&   Is this whitespace or an empty string?t    (   t   Truet   isspace(   t   string(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR    1   s     c         C   s1   y t  |   t SWn t t f k
 r, t SXd S(   s4   Does this object represent a floating point number? N(   t   floatR   t
   ValueErrort	   TypeErrort   False(   t   s(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR   6   s
    
c         C   s1   y t  |   t SWn t t f k
 r, t SXd S(   s&   Does this object represent an integer?N(   t   intR   R   R   R   (   R   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR   >   s
    
c         C   s1   t  j |  |  | k  r d S|  | k  r- d Sd S(   s   Floating point comparison.i    ii   (   t   matht   fabs(   t   xt   yt	   precision(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR   F   s
    c         C   s   d j  |  j    S(   s$   Remove all whitespace from a string.R   (   t   joint   split(   t   astring(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR   O   s    c         C   s/   t  g  |  j   D] \ } } | | f ^ q  S(   s   Constructs a new dictionary with inverted mappings so that keys become 
    values and vice versa. If the values of the original dictionary are not
    unique then only one of the original keys will be included in the new
    dictionary.
    (   t   dictt	   iteritems(   t
   dictionaryt   keyt   value(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR   U   s    c         K   sP   t  |  d  r |  j |  n- x* | j   D] \ } } t |  | |  q, W|  S(   sf   Update an instance with new values. 

    >>> update({'a': 1}, a=10, b=20)
    {'a': 10, 'b': 20}
    R   (   t   hasattrR   R)   t   setattr(   t   objt   entriest   kt   v(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR   ^   s
    c         C   s   | d k r |  j j } n  | d k r6 |  j j } n  g  } xJ | D]B } | d d k r_ qC n  | j d | t t |  |   f  qC Wd j |  j d d  } d | | f S(	   s.   Create a standard representation of an object.i    t   _s   %s=%ss   ,
s   
s   
    s   %s(
    %s
)N(	   t   Nonet	   __class__t   __name__t	   __slots__t   appendt   reprt   getattrR%   t   replace(   R/   t
   attributest   namet   argst   a(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR   l   s       *c         C   sI   d d l  m } g  | |   D]( \ } } | t d   | D  f ^ q S(   s   An iteration that returns tuples of items and the number of consecutive
    occurrences. Thus group_count('aabbbc') yields ('a',2), ('b',3), ('c',1)
    i(   t   groupbyc         s   s   |  ] } d  Vq d S(   i   N(    (   t   .0t   n(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pys	   <genexpr>|   s    (   t	   itertoolsR@   t   sum(   t   iR@   t   itemt   group(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR   w   s    c           B   sD   e  Z d  Z d d d d g Z d	 d d d  Z d   Z d   Z RS(
   sf  Represents the items returned by a file scanner, normally processed
    by a parser.
    
    Attributes :
    o typeof    -- a string describing the kind of token
    o data      -- the value of the token
    o lineno    -- the line of the file on which the data was found (if known)
    o offset    -- the offset of the data within the line (if known)
    t   typeoft   datat   linenot   offsetic         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   RH   RI   RJ   RK   (   t   selfRH   RI   RJ   RK   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   __init__   s    			c         C   s
   t  |   S(   N(   R   (   RL   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   __repr__   s    c         C   sv   t  |  j  } |  j d k r8 | d t  |  j  7} n  | j d  } | d |  j d j d  t  |  j pq d  S(   Nit   :i   s     s    : i    R   (   t   strRJ   RK   t   ljustRH   RI   (   RL   t   coord(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   __str__   s
     N(   R6   t
   __module__t   __doc__R7   R4   RM   RN   RS   (    (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR      s
   		c             sa   d   d   }   f d   } i  } |  j    | d <| | d <| | d <t   t f |  |    S(   s   Create a new instance of an anonymous class with the supplied attributes
    and values.
    
    >>> s = Struct(a=3,b=4)
    >>> s
    Struct(
        a=3,
        b=4
    )
    >>> s.a
    3
    
    R	   c         [   s1   x* | j    D] \ } } t |  | |  q Wd  S(   N(   R)   R.   (   R/   t   kwargsR1   R2   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   _init   s    c            s   t  |  |  j    S(   N(   R   R7   (   R/   (   R=   (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   _repr   s    R7   RM   RN   (   t   keyst   typet   object(   RV   RW   RX   t   adict(    (   R=   sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR	      s    	

c           B   s_   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   s6    A flexible wrapper around a simple iterator.    
    c         C   sG   t  | |   r | St j |   } t |  | _ g  | _ d | _ | S(   Ni    (   t
   isinstanceR[   t   __new__t   itert	   _iteratort   _stackt   _index(   t   clst   iteratort   new(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR^      s     		c         O   s   d  S(   N(    (   RL   R>   t   kw(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyRM      s    c         C   s   |  S(   N(    (   RL   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   __iter__   s    c         C   s6   |  j  d 7_  |  j r% |  j j   S|  j j   Sd S(   s&   Return the next item in the iteration.i   N(   Rb   Ra   t   popR`   t   next(   RL   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyRi      s    	c         C   s   |  j  S(   si   The number of items returned. Incremented by next(), decremented
        by push(), unchanged by peek()  (   Rb   (   RL   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   index   s    c         C   s#   |  j  d 8_  |  j j |  d S(   s/   Push an item back onto the top of the iterator,i   N(   Rb   Ra   R8   (   RL   RF   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   push   s    c         C   s:   y! |  j    } |  j |  | SWn t k
 r5 d SXd S(   s   Returns the next item, but does not advance the iteration.
        Returns None if no more items. (Bit may also return None as the
        next item.)N(   Ri   Rk   t   StopIterationR4   (   RL   RF   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   peek   s    c         C   s:   y! |  j    } |  j |  t SWn t k
 r5 t SXd S(   s   More items to return?N(   Ri   Rk   R   Rl   R   (   RL   RF   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   has_item   s    c         C   s/   |  j    } x | |  s* |  j    } q W| S(   sL   Return the next item in the iteration that satisfied the 
        predicate.(   Ri   (   RL   t	   predicateRi   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   filter   s     (   R6   RT   RU   R^   RM   Rg   Ri   Rj   Rk   Rm   Rn   Rp   (    (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR
      s   									c         C   s   d d l  } d | j |   S(   s;   Return the standard CRC32 checksum as a hexidecimal string.iNs   %08X(   t   binasciiR   (   R   Rq   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR     s    c         C   s)  t  d k r g  } x t d  D]~ } | } d } x\ t d  D]N } | d @} | d L} | d @ro | d O} n  | d L} | r> | d N} q> q> W| j |  q Wt |  a  n  d } d } x\ |  D]T }	 | d @d	 >}
 | d ?} | d ?|
 B} | t |	  Ad @} | t  | A} | } q Wd
 | | f S(   sG   Calculate ISO 3309 standard cyclic redundancy checksum.
    Used, for example, by SWISS-PROT.
    
    Returns : The CRC as a hexadecimal string.
    
    Reference: 
    o W. H. Press, S. A. Teukolsky, W. T. Vetterling, and B. P. Flannery,
     "Numerical recipes in C", 2nd ed., Cambridge University Press. Pages 896ff.
    i   i    i   i   l    i   l      0 i   i   s   %08X%08XNl        (   t   _crc64_tableR4   t   rangeR8   t   tuplet   ord(   R   t   tableRE   t   lt   part_ht   jt   rflagt   crclt   crcht   ct   shrt   temp1ht   temp1lt   idx(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR     s2    


 
 

c           B   sh   e  Z d  Z d d d d d g Z d d d  Z d   Z d   Z d	   Z d
   Z	 d   Z
 d   Z RS(   s  Line based random access to a file. Quickly turn a file into a read-only
    database.
    
    Attr:
    - indexfile -- The file to be indexed. Can be set to None and latter
                replaced with a new file handle, for exampel, if you need to
                close and latter reopen the file. 
    
    Bugs:
        User must set the indexedfile to None before pickling this class.  
    
    t   indexedfilet   _parsert
   _positionst   _keyst	   _key_dictc   
      C   s  d   } | d k r | } n  | |  _ | j d  g  } g  } xs t r | j   } | j   } | d k rq Pn  | r | |  }	 |	 d k r qC n  | j |	  n  | j |  qC W| |  _ t |  |  _	 | r t |  |  _
 t t | |   |  _ n  d S(   s  
            
        Args:
        - indexedfile -- The file to index
        - linekey -- An optional function. keyofline() will be passed each line
            of the file in turn and should return a string to index the line, 
            or None. If keyofline() is supplied, then only lines that generate  
            keys are indexed.
        - parser -- An optional parser. A function that reads from a file handle
            positioned at the start of a record and returns an object.   
        c         S   s
   |  j    S(   N(   t   readline(   t
   seekedfile(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   default_parserM  s    i    R   N(   R4   R   t   seekR   t   tellR   R8   R   Rt   R   R   R(   t   zipR   (
   RL   R   t   linekeyt   parserR   t	   positionsRY   t   positiont   lineR1   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyRM   @  s.    	 			  	c         C   s0   t  | t  r |  j | } n |  j | } | S(   N(   R]   RP   R   R   (   RL   RF   t   p(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR   k  s    c         C   s   |  j  j |  j |   d S(   s+   Seek the indexfile to the position of item.N(   R   R   R   (   RL   RF   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR   r  s    c         c   s-   x& t  d t |    D] } |  | Vq Wd  S(   Ni    (   Rs   t   len(   RL   RE   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyRg   v  s    c         C   s   t  |  j  S(   N(   R   R   (   RL   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   __len__z  s    c         C   s)   |  j  j |  j |   |  j |  j   S(   N(   R   R   R   R   (   RL   RF   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   __getitem__}  s    c         C   s?   y |  j  |  t SWn# t k
 r) t St k
 r: t SXd  S(   N(   R   R   t   KeyErrorR   t
   IndexError(   RL   RF   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   __contains__  s    N(   R6   RT   RU   R7   R4   RM   R   R   Rg   R   R   R   (    (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR   1  s   +					c         C   s   d d l  } | d k rT t j j d d  j t j  } | d g k rT d } qT n  y | j |  |  j   } Wn& t	 k
 r | _
 t d |    n X| S(   s  Return the full path to the first match of the given command on
    the path.
    
    Arguments:
    - command -- is a the name of the executable to search for.
    - path -- is an optional alternate path list to search. The default is
        to use the COREBIOPATH environment variable, if it exists, else the 
        PATH environment variable.
        
    Raises:
    - EnvironmentError -- If no match is found for the command.
    
    By default the COREBIOPATH or PATH environment variable is searched (as well
    as, on Windows, the AppPaths key in the registry), but a specific 'path'
    list to search may be specified as well.  
        
    Author: Adapted from code by Trent Mick (TrentM@ActiveState.com)
    See: http://trentm.com/projects/which/
    iNt   COREBIOPATHR   s    Could not find '%s' on the path.(   t   _whichR4   t   ost   environt   getR&   t   pathsept   whichgenRi   Rl   t
   WhichErrort   EnvironmentError(   t   commandt   pathR   t   match(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR     s    ! c           B   s   e  Z d  Z d d  Z RS(   s;   A subclass of ValueError raised when a function receives an argument
    that has the right type but an inappropriate value, and the situation is not
    described by a more precise exception such as IndexError. The name of the   
    argument or component at fault and (optionally) the value are also stored.
    c         C   s2   t  j |  | |  | |  _ | |  _ | |  _ d S(   s    Args:
        - msg -- An error message.
        - key -- The name of the argument or component at fault.
        - value -- Optional value of the argument.
        N(   R   RM   t   msgR+   R,   (   RL   t   messageR+   R,   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyRM     s    		N(   R6   RT   RU   R4   RM   (    (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR     s   c           B   sq   e  Z d  Z d   Z e e  Z e Z e Z e Z e Z e Z	 e Z
 e Z d   Z d   Z d   Z d   Z RS(   s   A frozendict is a dictionary that cannot be modified after being created
     -  but it is hashable and may serve as a member of a set or a key in a
    dictionary.
    # Author: Adapted from code by Oren Tirosh
    c         C   s   t  d  d  S(   Ns    A frozendict cannot be modified.(   t   AttributeError(   R/   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   _blocked_attribute  s    c         O   s&   t  j |   } t  j | | |  | S(   N(   R(   R^   RM   (   Rc   R>   Rf   Re   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR^     s    c         O   s   d  S(   N(    (   RL   R>   Rf   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyRM     s    c         C   sI   y |  j  SWn7 t k
 rD t t t |  j      } |  _  | SXd  S(   N(   t   _cached_hashR   t   hashRt   t   sortedRY   (   RL   t   h(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   __hash__  s
    %c         C   s   d t  j |   S(   Ns   frozendict(%s)(   R(   RN   (   RL   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyRN     s    (   R6   RT   RU   R   t   propertyt   __delitem__t   __setitem__t   clearRh   t   popitemt
   setdefaultR   R^   RM   R   RN   (    (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR     s   				c         C   s2   t  r t  j |  |  St |  | |  } | j   S(   so   Locate and return a resource as a string.
    >>> f = resource_string( __name__, 'somedatafile', __file__)
    (   t   pkg_resourcesR   R   t   read(   t
   modulenamet   resourcet   basefilenamet   f(    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR     s    c         C   s,   t  r t  j |  |  St t |  | |   S(   so   Locate and return a resource as a stream.
    >>> f = resource_stream( __name__, 'somedatafile', __file__)
    (   R   R   t   openR   (   R   R   R   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR     s    c         C   s\   t  r t  j |  |  S| d k r1 t d   n  d d l } | j j | j j |  |  S(   s  Locate and return a resource filename.
    >>> f = resource_filename( __name__, 'somedatafile', __file__)

    A resource is a data file stored with the python code in a package.
    All three resource methods (resource_string,  resource_stream,
    resource_filename) call the corresponding methods in the 'pkg_resources'
    module, if installed. Otherwise, we resort to locating the resource
    in the local filesystem. However, this does not work if the package
    is located inside a zip file. 
    s,   Require either basefilename or pkg_resourcesiN(   R   R   R4   t   NotImplementedErrorR   R   R%   t   dirname(   R   R   R   R   (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyR     s    (   s   isblanks   isfloats   isints   fcmps   remove_whitespaces   invert_dicts   updates   stdreprs   Tokens   Structs	   ReiterateR   s   crc32s   crc64s	   FileIndexs   find_commands   ArgumentErrors
   frozendicts   group_counts   resource_strings   resource_streams   resource_filename(!   RU   t   __all__t   os.pathR   R    R   t   ImportErrorR4   R    R   R   R   R   R   R   R   R   R[   R   R	   R
   R   Rr   R   R   R   R   R   R(   R   R   R   R   (    (    (    sL   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/utils/__init__.pyt   <module>   sB       
											D		)\!+
	