
:>"^§  ã               @   s–   d  Z  d d „  Z d d „  Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z d	 d
 „  Z d d „  Z d d „  Z d d „  Z	 d d „  Z
 d d „  Z d S)aê  Code to work with the prosite.doc file from Prosite.

See https://www.expasy.org/prosite/

Tested with:
 - Release 15.0, July 1998
 - Release 16.0, July 1999
 - Release 20.22, 13 November 2007
 - Release 20.43, 10 February 2009

Functions:
 - read               Read a Prodoc file containing exactly one Prodoc entry.
 - parse              Iterates over entries in a Prodoc file.

Classes:
 - Record             Holds Prodoc data.
 - Reference          Holds data from a Prodoc reference.

c             C   s.   t  |  ƒ } |  j ƒ  } | r* t d ƒ ‚ | S)z<Read in a record from a file with exactly one Prodoc record.z!More than one Prodoc record found)Ú__readÚreadlineÚ
ValueError)ÚhandleÚrecordÚline© r   ú6/tmp/pip-build-ww9dw3qa/biopython/Bio/ExPASy/Prodoc.pyÚread   s
    r	   c             c   s&   x t  |  ƒ } | s d S| Vq Wd S)z*Iterate over the records in a Prodoc file.N)r   )r   r   r   r   r   Úparse%   s
    r
   c               @   s"   e  Z d  Z d Z d d „  Z d S)ÚRecorda  Holds information from a Prodoc record.

    Attributes:
     - accession      Accession number of the record.
     - prosite_refs   List of tuples (prosite accession, prosite name).
     - text           Free format text.
     - references     List of reference objects.

    c             C   s(   d |  _  g  |  _ d |  _ g  |  _ d S)zInitialize the class.Ú N)Ú	accessionÚprosite_refsÚtextÚ
references)Úselfr   r   r   Ú__init__9   s    			zRecord.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   .   s   	r   c               @   s"   e  Z d  Z d Z d d „  Z d S)Ú	ReferencezÆHolds information from a Prodoc citation.

    Attributes:
     - number     Number of the reference. (string)
     - authors    Names of the authors.
     - citation   Describes the citation.

    c             C   s   d |  _  d |  _ d |  _ d S)zInitialize the class.r   N)ÚnumberÚauthorsÚcitation)r   r   r   r   r   K   s    		zReference.__init__N)r   r   r   r   r   r   r   r   r   r   A   s   r   c             C   se   | j  ƒ  } | d d k r, t d | ƒ ‚ | d d … j d ƒ \ } } |  j j | | f ƒ d  S)Né   Ú}z3I don't understand the Prosite reference on line
%sz; éÿÿÿÿr   )Úrstripr   Úsplitr   Úappend)r   r   ÚaccÚnamer   r   r   Ú__read_prosite_reference_lineU   s
    r#   c             C   s   |  j  | 7_  d S)NT)r   )r   r   r   r   r   Ú__read_text_line]   s    r$   c             C   s{   t  ƒ  } | d d … j ƒ  | _ | d d k rN | d d  … j ƒ  | _ n | d d  … j ƒ  | _ |  j j | ƒ d  S)Nr   é   ÚEé   )r   Ústripr   r   r   r   r    )r   r   Ú	referencer   r   r   Ú__read_reference_startb   s    	r*   c             C   s’   | j  ƒ  s d S|  j d	 } | j d ƒ r~ | j d
 d k ra | j | d d  … j ƒ  7_ n | j | d d  … 7_ d St d | ƒ ‚ d  S)NFr   z     ú,r'   é   Tz(I don't understand the reference line
%sr   r   )r(   r   Ú
startswithr   r   r   Ú	Exception)r   r   r)   r   r   r   Ú__read_reference_lineo   s    "r/   c             C   s   | j  d ƒ r d Sd S)Nz+----FT)r-   )r   r   r   r   r   Ú__read_copyright_line|   s    r0   c             C   sÚ  x5 |  D]) } | j  ƒ  } | r | j d ƒ r Pq Wd  St ƒ  } | j d ƒ s` t d | ƒ ‚ | d d k r€ t d | ƒ ‚ | d d … | _ x: |  D]& } | j d ƒ r¿ t | | ƒ qš Pqš Wt d ƒ ‚ | j d	 ƒ sï t d
 | ƒ ‚ t } xÒ |  D]Ê } | j d ƒ rMx5 | j D]* } | j j  ƒ  | _ | j	 j  ƒ  | _	 qW| S| d d k r“| d d k r“| d d k r“t
 | | ƒ t } qü | j d ƒ r«t } qü | rü | | | ƒ sü d  } qü Wt d ƒ ‚ d  S)Nz//z{PDOCz$Line does not start with '{PDOC':
%sr   r   z$I don't understand accession line
%sz{PSzUnexpected end of stream.z{BEGINz%Line does not start with '{BEGIN':
%sz{END}é    ú[r%   ú]r'   ú z+----r   r   )r   r-   r   r   r   r#   r$   r   r   r   r*   r/   r0   )r   r   r   Z	read_liner)   r   r   r   r   ƒ   sD    	0		
r   N)r   r	   r
   Úobjectr   r   r#   r$   r*   r/   r0   r   r   r   r   r   Ú<module>   s   
	