ó
¾N/Ic           @   sl   d  Z  d d l Z d d l Z d d l Z d d l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ e Z d S(   sø   Index.py

This module provides a way to create indexes to text files.

Classes:
Index     Dictionary-like class used to store index information.

_ShelveIndex    An Index class based on the shelve module.
_InMemoryIndex  An in-memory Index class.

iÿÿÿÿNt   _ShelveIndexc           B   s/   e  Z d  Z d Z d Z d d „ Z d „  Z RS(   s*   An index file wrapped around shelve.

    i   t	   __versionc         C   s#  t  j |  ƒ y | rs | d | d | d g } x0 | D]( } t j j | ƒ r8 t j | ƒ q8 q8 Wt d ƒ ‚ n  t j | d d ƒ|  _	 Wn2 t j | d d ƒ|  _	 |  j
 |  j	 |  j <n_ X|  j	 j |  j d  ƒ } | d  k rô t d ƒ ‚ n+ | |  j
 k rt d	 | |  j
 f ƒ ‚ n  d  S(
   Ns   .dirs   .dats   .baks   open a new shelft   flagt   rt   ns   Unrecognized index formats&   Version %s doesn't match my version %s(   t   dictt   __init__t   ost   patht   existst   unlinkt	   Exceptiont   shelvet   opent   datat   _ShelveIndex__versiont   _ShelveIndex__version_keyt   gett   Nonet   IOError(   t   selft	   indexnamet   truncatet   filest   filet   version(    (    s|   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Index.pyR   "   s(    c         C   s&   |  j  j d ƒ r" |  j j ƒ  n  d  S(   NR   (   t   __dict__t   has_keyR   t   close(   R   (    (    s|   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Index.pyt   __del__>   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   (    (    (    s|   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Index.pyR       s
   t   _InMemoryIndexc           B   se   e  Z d  Z d Z d Z d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z RS(   s+   This creates an in-memory index file.

    i   R   c         C   s  | |  _  t j |  ƒ d |  _ | rP t j j | ƒ rP t j | ƒ d |  _ n  t j j | ƒ rt | ƒ } |  j	 | j
 ƒ  j ƒ  ƒ } | |  j k r´ t d | |  j f ƒ ‚ n  xI | D]A } | j ƒ  \ } } |  j	 | ƒ |  j	 | ƒ } } | |  | <q» Wd |  _ n  d  S(   Ni    i   s&   Version %s doesn't match my version %s(   t
   _indexnameR   R   t   _InMemoryIndex__changedR   R   R	   R
   R   t   _toobjt   readlinet   rstript   _InMemoryIndex__versionR   t   split(   R   R   R   t   handleR   t   linet   keyt   value(    (    s|   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Index.pyR   N   s"    		c         C   s   d |  _  | j |  | ƒ d  S(   Ni   (   R#   t   update(   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/Index.pyR-   e   s    	c         C   s    d |  _  t j |  | | ƒ d  S(   Ni   (   R#   R   t   __setitem__(   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/Index.pyR.   h   s    	c         C   s   d |  _  t j |  | ƒ d  S(   Ni   (   R#   R   t   __delitem__(   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/Index.pyR/   k   s    	c         C   s   d |  _  t j |  ƒ d  S(   Ni   (   R#   R   t   clear(   R   (    (    s|   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Index.pyR0   n   s    	c         C   s   |  j  r‹ t |  j d ƒ } | j d |  j |  j ƒ ƒ xC |  j ƒ  D]5 \ } } | j d |  j | ƒ |  j | ƒ f ƒ qE W| j ƒ  n  d  S(   Nt   ws   %s
s   %s %s
(   R#   R   R"   t   writet   _tostrR'   t   itemsR   (   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/Index.pyR   r   s    		$c         C   s=   t  j | ƒ } t j d | ƒ } t t | ƒ } d j | ƒ S(   Nt   bt   ,(   t   cPicklet   dumpst   arrayt   mapt   strt   join(   R   t   objt   st   intlistt   strlist(    (    s|   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Index.pyR3   {   s    c         C   sO   t  t | j d ƒ ƒ } t j d | ƒ } t  t | ƒ } t j d j | ƒ ƒ S(   NR6   R5   t    (   R:   t   intR(   R9   t   chrR7   t   loadsR<   (   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/Index.pyR$   ˆ   s    N(   R   R   R    R'   t   _InMemoryIndex__version_keyR   R   R-   R.   R/   R0   R   R3   R$   (    (    (    s|   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Index.pyR!   B   s   							(	   R    R   R9   R7   R   R   R    R!   t   Index(    (    (    s|   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Index.pyt   <module>   s   ,L