B
    ‰°b¦  ã               @   s&   d Z G dd„ deƒZG dd„ dƒZdS )z<Objects to represent NEXUS standard data type matrix coding.c               @   s   e Zd ZdZdS )Ú
NexusErrorz1Provision for the management of Nexus exceptions.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   ú5lib/python3.7/site-packages/Bio/Nexus/StandardData.pyr      s   r   c               @   sH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dS )ÚStandardDatazCreate a StandardData iterable object.

    Each coding specifies t [type] => (std [standard], multi [multistate] or
    uncer [uncertain]) and d [data]
    c             C   s  g | _ d| _t|tƒstdƒ‚d}d}dg dœ}xÎt|ƒD ]Â\}}|rf|dkrTd}qâ|d  |¡ q:n||rŠ|dkrxd}qâ|d  |¡ q:nX|d	kr¢d
}d|d< q:n@|dkrºd
}d|d< q:n(|dkrÔtd||f ƒ‚n|d  |¡ | j  | ¡ ¡ dg dœ}q:W dS )zInitialize the class.é    zAThe coding data given to a StandardData object should be a stringFZstd)ÚtÚdú)r   Ú}ú(TÚmultir
   Ú{Úuncer)r   r   z:Improper character %s at position %i of a coding sequence.N)Ú_dataÚ_current_posÚ
isinstanceÚstrr   Ú	enumerateÚappendÚcopy)ÚselfÚdataZmulti_codingZuncertain_codingZcoding_listÚposÚcodingr   r   r   Ú__init__   sD    

zStandardData.__init__c             C   s
   t | jƒS )z4Return the length of the coding, use len(my_coding).)Úlenr   )r   r   r   r   Ú__len__R   s    zStandardData.__len__c             C   s
   | j | S )zPull out child by index.)r   )r   Úargr   r   r   Ú__getitem__V   s    zStandardData.__getitem__c             C   s   | S )zIterate over the items.r   )r   r   r   r   Ú__iter__Z   s    zStandardData.__iter__c             C   sH   y| j | j }W n  tk
r0   d| _td‚Y nX |  jd7  _|S dS )zReturn next item.r	   Né   )r   r   Ú
IndexErrorÚStopIteration)r   Zreturn_codingr   r   r   Ú__next__^   s    zStandardData.__next__c             C   s   | j S )z(Return the full coding as a python list.)r   )r   r   r   r   Úrawi   s    zStandardData.rawc             C   sx   d}xn| j D ]d}|d dkr8|dd |d ¡ d 7 }q|d dkr`|dd |d ¡ d	 7 }q||d d
 7 }qW |S )z>Return the full coding as a python string, use str(my_coding).Ú r
   r   r   r   r   r   r   r   r	   )r   Újoin)r   Z
str_returnr   r   r   r   Ú__str__m   s    zStandardData.__str__N)r   r   r   r   r   r   r!   r"   r&   r'   r*   r   r   r   r   r      s   8r   N)r   Ú	Exceptionr   r   r   r   r   r   Ú<module>
   s   