B
    ‰°b—  ã               @   sd   d Z dd„ Zdd„ ZG dd„ dƒZG dd„ dƒ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 | ƒ}|  ¡ }|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   ú0lib/python3.7/site-packages/Bio/ExPASy/Prodoc.pyÚread   s
    r	   c             c   s    xt | ƒ}|sdS |V  qW d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   sJ   |  ¡ }|d dkr td| ƒ‚|dd…  d¡\}}| j ||f¡ d S )NéÿÿÿÿÚ}z3I don't understand the Prosite reference on line
%sé   z; )Úrstripr   Úsplitr   Úappend)r   r   Z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   sZ   t ƒ }|dd…  ¡ |_|d dkr8|dd …  ¡ |_n|dd …  ¡ |_| j |¡ d S )Nr   é   ÚEé   )r   Ústripr   r   r   r   r    )r   r   Ú	referencer   r   r   Ú__read_reference_startb   s    r)   c             C   st   |  ¡ sdS | jd }| d¡rd|jd dkrJ| j|dd …  ¡ 7  _n| j|dd … 7  _dS td| ƒ‚d S )	NFr   z     ú,r&   é   Tz(I don't understand the reference line
%s)r'   r   Ú
startswithr   r   r   Ú	Exception)r   r   r(   r   r   r   Ú__read_reference_lineo   s    

r.   c             C   s   |  d¡rdS dS )Nz+----FT)r,   )r   r   r   r   r   Ú__read_copyright_line|   s    
r/   c             C   sb  x(| D ]}|  ¡ }|r| d¡sP qW d S tƒ }| d¡sFtd| ƒ‚|d dkr^td| ƒ‚|dd… |_x,| D ]}| d¡rŒt||ƒ qrP qrW td	ƒ‚| d
¡s°td| ƒ‚t}x | D ]˜}| d¡rôx&|jD ]}|j  ¡ |_|j	  ¡ |_	qÐW |S |d dkr.|d dkr.|d dkr.t
||ƒ t}qº| d¡r@t}qº|rº|||ƒsºd }qºW td	ƒ‚d S )Nz//z{PDOCz$Line does not start with '{PDOC':
%sr   r   z$I don't understand accession line
%sr   z{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   r   r   Z	read_liner(   r   r   r   r   ƒ   sD    






*

r   N)r   r	   r
   r   r   r"   r#   r)   r.   r/   r   r   r   r   r   Ú<module>   s   
	