
:>"^:                 @   s   d  Z  d d d d d d d d i Z d	 d
 d d d d d d d d i Z d d d d i Z d d d d d d d d d d d d d d  i Z d$ Z Gd! d"   d" e  Z d# S)%aQ  Calculate isoelectric points of polypeptides using methods of Bjellqvist.

pK values and the methos are taken from::

    * Bjellqvist, B.,Hughes, G.J., Pasquali, Ch., Paquet, N., Ravier, F.,
    Sanchez, J.-Ch., Frutiger, S. & Hochstrasser, D.F.
    The focusing positions of polypeptides in immobilized pH gradients can be
    predicted from their amino acid sequences. Electrophoresis 1993, 14,
    1023-1031.

    * Bjellqvist, B., Basse, B., Olsen, E. and Celis, J.E.
    Reference points for comparisons of two-dimensional maps of proteins from
    different human cell types defined in a pH scale where isoelectric points
    correlate with polypeptide compositions. Electrophoresis 1994, 15, 529-539.

I designed the algorithm according to a note by David L. Tabb, available at:
http://fields.scripps.edu/DTASelect/20010710-pI-Algorithm.pdf
Ntermg      @Kg      $@Rg      (@HgQ@Ctermgffffff@Dg333333@Eg@Cg      "@Yg333333@g      @Ag\(\@Mg      @SgQ@PgQ @TgHzG@Vg(\@g@c               @   sa   e  Z d  Z d Z d d d  Z d d   Z d d   Z d	 d
   Z d d   Z d d   Z	 d S)IsoelectricPointa  A class for calculating the IEP or charge at given pH of a protein.

    Parameters
    ----------
    :protein_sequence: A ``Bio.Seq`` or string object containing a protein
                       sequence.
    :aa_content: A dictionary with amino acid letters as keys and it's
                 occurences as integers, e.g. ``{"A": 3, "C": 0, ...}``.
                 Default: ``None``. If ``None``, the dic will be calculated
                 from the given sequence.

    Methods
    -------
    :charge_at_pH(pH):  Calculates the charge of the protein for a given pH
    :pi():              Calculates the isoelectric point


    Examples
    --------
    The methods of this class can either be accessed from the class itself
    or from a ``ProtParam.ProteinAnalysis`` object (with partially different
    names):

    >>> from Bio.SeqUtils.IsoelectricPoint import IsoelectricPoint as IP
    >>> protein = IP("INGAR")
    >>> print("IEP of peptide {} is {:.2f}"
    ...       .format(protein.sequence, protein.pi()))
    IEP of peptide INGAR is 9.75
    >>> print("It's charge at pH 7 is {:.2f}"
    ...       .format(protein.charge_at_pH(7.0)))
    It's charge at pH 7 is 0.76


    >>> from Bio.SeqUtils.ProtParam import ProteinAnalysis as PA
    >>> protein = PA("PETER")
    >>> print("IEP of {}: {:.2f}".format(protein.sequence,
    ...                                  protein.isoelectric_point()))
    IEP of PETER: 4.53
    >>> print("Charge at pH 4.53: {:.2f}"
    ...       .format(protein.charge_at_pH(4.53)))
    Charge at pH 4.53: 0.00

    Nc             C   sn   t  |  j   |  _ | s@ d d l m } | |  j  j   } |  j |  |  _ |  j   \ |  _	 |  _
 d S)zInitialize the class.    )ProteinAnalysisN)struppersequenceZBio.SeqUtils.ProtParamr   Zcount_amino_acids_select_chargedcharged_aas_content_update_pKs_tablespos_pKsneg_pKs)selfZprotein_sequence
aa_contentZ_PA r   B/tmp/pip-build-ww9dw3qa/biopython/Bio/SeqUtils/IsoelectricPoint.py__init__U   s    zIsoelectricPoint.__init__c             C   sC   i  } x" t  D] } t | |  | | <q Wd | d <d | d <| S)Ng      ?r   r   )charged_aasfloat)r   r   Zchargedaar   r   r   r   b   s    

z IsoelectricPoint._select_chargedc             C   sq   t  j   } t j   } |  j d |  j d } } | t k rM t | | d <| t k rg t | | d <| | f S)z@Update pKs tables with seq specific values for N- and C-termini.r      r   r   )positive_pKscopynegative_pKsr   pKnterminalpKcterminal)r   r   r   ZntermZctermr   r   r   r   j   s    z#IsoelectricPoint._update_pKs_tablesc             C   s   d } xN |  j  j   D]= \ } } d | | } | | d } | |  j | | 7} q Wd } xN |  j j   D]= \ } } d | | } | | d } | |  j | | 7} qm W| | S)Ng        
   g      ?)r   itemsr   r   )r   pHZpositive_charger"   ZpKCRZpartial_chargeZnegative_charger   r   r   _chargeRv   s    zIsoelectricPoint._chargeRc             C   s   |  j  |  S)z.Calculate the charge of a protein at given pH.)r.   )r   r,   r   r   r   charge_at_pH   s    zIsoelectricPoint.charge_at_pHc             C   sO  d } |  j  |  } | d k r | } | } x | d k r | d } |  j  |  } | d k rp | } | } q0 | } | } Pq0 Wn` | } | } xQ | d k  r | d } |  j  |  } | d k  r | } | } q | } | } Pq Wxd | | d k rJ| d k rJ| | d } |  j  |  } | d k r;| } | } q | } | } q W| S)z4Calculate and return the isoelectric point as float.   g        g      ?g-C6?g       @)r.   )r   r,   ZchargeZpH1Zcharge1ZpH2Zcharge2r   r   r   pi   sD    
	
		
zIsoelectricPoint.pi)
__name__
__module____qualname____doc__r   r   r   r.   r/   r1   r   r   r   r   r   (   s   +r   N)r   r   r   r   r   r   r	   )r5   r%   r'   r)   r(   r    objectr   r   r   r   r   <module>   s   $