o
    Rŀg                     @   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   J/var/www/html/myenv/lib/python3.10/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}t|D ]\\}}|r1|dkr)d}nB|d | q|rB|dkr:d}n1|d | q|d	krMd
}d|d< q|dkrXd
}d|d< q|dv rdtd||f |d | | j |  dg d}qdS )zInitialize the class.    zAThe coding data given to a StandardData object should be a stringF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datamulti_codinguncertain_codingcoding_listposcodingr   r   r   __init__   sL   

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__P      
zStandardData.__len__c                 C   s
   | j | S )zPull out child by index.r   )r   argr   r   r   __getitem__T   r%   zStandardData.__getitem__c                 C   s   | S )zIterate over the items.r   r#   r   r   r   __iter__X   s   zStandardData.__iter__c                 C   s>   z| j | j }W n ty   d| _tdw |  jd7  _|S )zReturn next item.r	   N   )r   r   
IndexErrorStopIteration)r   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   rawg   s   zStandardData.rawc                 C   st   d}| j D ]2}|d dkr|dd|d  d 7 }q|d dkr/|dd|d  d	 7 }q||d d
 7 }q|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   
str_returnr    r   r   r   __str__k   s   
zStandardData.__str__N)r   r   r   r   r!   r$   r(   r)   r.   r/   r3   r   r   r   r   r      s    8r   N)r   	Exceptionr   r   r   r   r   r   <module>   s   	