ó
X<c           @   s)   d  Z  d d l Z d d d     YZ d S(   s   Methods for performing repairs that will Stabilize genomes.

These methods perform repair to keep chromosomes from drifting too far in
any direction -- ie. bring them back to a stabilizing center. This may be
useful in cases where fitness functions alone won't keep chromosomes in
check.
i˙˙˙˙Nt   AmbiguousRepairc           B   s    e  Z d  Z d   Z d   Z RS(   sŹ  Perform repair to reduce the number of Ambiguous genes in a genome.

    In cases where ambiguous genes are allowed in a genome (for example,
    where you have a wild card character like '*' that will match
    anything), these can come to dominate a genome since, really, the
    best fitness is someting like '*******'. This repair protects against
    that by changing ambiguous characters into some non-ambiguous gene.
    c         C   s%   | |  _  | |  _ | j   |  _ d S(   sđ  Initialize the repair class.

        Arguments:

        o ambig_finder - A class implementing the function find_ambiguous
        which will return a list of all ambiguous positions in a sequence.
        It also must have the function all_unambiguous, which will return
        all allowed unambiguous letters.

        o num_ambiguous - The minimum number of ambiguous items that are
        allowed in a genome. If there are more than this present, repair
        will be performed.
        N(   t   _ambig_findert   _num_ambiguoust   all_unambiguoust   _alphabet_letters(   t   selft   ambig_findert   num_ambiguous(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/GA/Repair/Stabilizing.pyt   __init__   s    		c         C   s   | j    } xo | j j   } |  j j | j  } t |  |  j k rL Pn  t j	 |  } t j	 |  j
  } | | j | <q W| S(   s;   Perform a repair to remove excess ambiguous genes.
        (   t   copyt   genomet   toseqR   t   find_ambiguoust   datat   lenR   t   randomt   choiceR   (   R   t   organismt   new_orgt
   seq_genomet   all_ambiguoust	   to_changet   new_gene(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/GA/Repair/Stabilizing.pyt   repair&   s    (   t   __name__t
   __module__t   __doc__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/GA/Repair/Stabilizing.pyR       s   	(    (   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/GA/Repair/Stabilizing.pyt   <module>   s   