ó
¨Ic           @   s   d  Z  d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d	  Z d
   Z	 d d  Z
 y d d l TWn e k
 r n Xd S(   s  This provides useful general functions for working with lists (OBSOLETE).

This module and its C code equivalent are considered to be obsolete, and
are likely to be deprecated in a future release of Biopython, before being
removed.  Please get in touch via the mailing list if this will affect you.
Many of these functions can be avoided using the python set object.

Functions:
asdict        Make the list into a dictionary (for fast testing of membership).
items         Get one of each item in a list.
count         Count the number of times each item appears.
contents      Calculate percentage each item appears in a list.
itemindex     Make an index of the items in the list.
intersection  Get the items in common between 2 lists.
difference    Get the items in 1 list, but not the other.
indexesof     Get a list of the indexes of some items in a list.
take          Take some items from a list.

c         C   s
   t  |   S(   sŹ   asdict(l) -> dictionary

    Return a dictionary where the keys are the items in the list, with
    arbitrary values.  This is useful for quick testing of membership.

    (   t   count(   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/listfns.pyt   asdict   s    c         C   sŻ   y t  |   j   SWn4 t k
 rJ } t |  j d  d k rK   qK n X|  }  |  j   d } xF | t |   d k  rŞ |  | |  | d k r |  | =qe | d 7} qe W|  S(   s~   items(l) -> list of items

    Generate a list of one of each item in l.  The items are returned
    in arbitrary order.

    t
   unhashablei˙˙˙˙i    i   (   R   t   keyst	   TypeErrort   strt   findt   sortt   len(   R   t   xt   i(    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/listfns.pyt   items#   s    


c         C   s5   i  } x( |  D]  } | j  | d  d | | <q W| S(   su   count(items) -> dict of counts of each item

    Count the number of times each item appears in a list of data.

    i    i   (   t   get(   R   t   cR   (    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/listfns.pyR    ;   s    c         C   sS   t  |   } t t |    } i  } x( | j   D] \ } } | | | | <q1 W| S(   sć   contents(items) -> dict of item:percentage

    Summarize the contents of the list in terms of the percentages of each
    item.  For example, if an item appears 3 times in a list with 10 items,
    it is in 0.3 of the list.

    (   R    t   floatR	   R   (   R   t   countsR   t   contentsR   R   (    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/listfns.pyR   F   s    c         C   sM   g  } t  |   } x4 | D], } | j |  r | j |  | | =q q W| S(   s   intersection(l1, l2) -> list of common items

    Return a list of the items in both l1 and l2.  The list is in
    arbitrary order.

    (   R    t   has_keyt   append(   t   l1t   l2t   intert   words1t   w(    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/listfns.pyt   intersectionU   s    c         C   sP   g  } t  |  } x7 |  D]/ } | j |  s | j |  d | | <q q W| S(   s   difference(l1, l2) -> list of items in l1, but not l2
    
    Return a list of the items in l1, but not l2.  The list is in
    arbitrary order.

    i   (   R    R   R   (   R   R   t   difft   words2R   (    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/listfns.pyt
   differenced   s    c         C   sK   i  } x> t  t |    D]* } | j |  |  s | | |  | <q q W| S(   să   itemindex(l) -> dict of item : index of item

    Make an index of the items in the list.  The dictionary contains
    the items in the list as the keys, and the index of the first
    occurrence of the item as the value.

    (   t   rangeR	   R   (   R   t   dictR   (    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/listfns.pyt	   itemindexs   s
    i    c         C   sa   g  } xT t  t |    D]@ } | |  |  } | r< | sI | r | r | j |  q q W| S(   sa   indexesof(l, fn) -> list of indexes

    Return a list of indexes i where fn(l[i]) is true.

    (   R   R	   R   (   R   t   fnt   oppositet   indexesR   t   f(    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/listfns.pyt	   indexesof   s    c         C   s,   g  } x | D] } | j  |  |  q W| S(   s3   take(l, indexes) -> list of just the indexes from l(   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/listfns.pyt   take   s    c         C   s"   t  |  | d | } t |  |  S(   NR!   (   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/listfns.pyt	   take_byfn   s    i˙˙˙˙(   t   *N(   t   __doc__R   R   R    R   R   R   R   R$   R%   R&   t   clistfnst   ImportError(    (    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/listfns.pyt   <module>   s   									