o
    Rŀg}                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ d	d
 Zdd Zdd Zdd Zdd ZG dd deZdS )zBio.SeqIO support for the "gck" file format.

The GCK binary format is generated by the Gene Construction Kit software
from Textco BioSoftware, Inc.
    )unpack)Seq)
SeqFeature)SimpleLocation)	SeqRecord   )SequenceIteratorc                 C   s*   |  |}t||k rtd| d|S )z9Read the specified number of bytes from the given handle.zCannot read z bytes from handle)readlen
ValueErrorhandlelengthdata r   C/var/www/html/myenv/lib/python3.10/site-packages/Bio/SeqIO/GckIO.py_read   s   
r   c                 C   s*   t | d}td|d }t | |}||fS )aL  Read a length-prefixed packet.

    Parts of a GCK file are made of "packets" comprising of 4 bytes
    giving the packet's size, followed by the packet's data.

    There is no type tag. The type of a packet, and thus the type of data
    it contains, is solely indicated by the position of the packet within
    the GCK file.
       >Ir   )r   r   r   r   r   r   _read_packet   s   


r   c                 C   ,   t | d}td|d }t | |d}|S )zeRead a Pascal string.

    A Pascal string is one byte for length followed by the actual string.
    r   z>Br   ASCIIr   r   decoder   r   r   r   _read_pstring/      
r   c                 C   r   )zcRead a 32-bit Pascal string.

    Similar to a Pascal string but length is encoded on 4 bytes.
    r   r   r   r   r   r   r   r   r   _read_p4string:   r   r   c                 c   s&   |  d}|stdt|dk rtdt| \}}td|d d d }||d kr1td|dd  d}tt|}t|  t| \}}td	|d d
 \}}|t|kr_td|d
 |d krktdt|D ]c}d
|d  }	||	|	d  }
td|
\}}}}}}}|dkrd}nd}t	|||d}|dkrd}nd}i }|dkrt
| }|g|d< |dkrt| }|g|d< |dkrqot|||d}|j| qot| \}}td	|d d
 \}}|d
 |d krtdt|D ]'}d
|d  }	||	|	d  }td|\}}}}|rt
|  |rt|  qt|  t| d}td|d }t| |d }t|D ]#}|d }	||	|	d  }td|dd  d }|dkrYt|  q7t| d t
| }|dd  |_|_||_t| d}td |d }|dkrd!|jd"< nd#|jd"< |V  d S )$N   zEmpty file.z1Improper header, cannot read 24 bytes from handler   r   r   z"Conflicting sequence length valuesr   z>IH   \   z9Features packet size inconsistent with number of featuresz>II6xH14xB17xII35xBr   )strandCDSmisc_featurelabelnote)type
qualifiersX   z3Sites packet size inconsistent with number of sitesz>II24xII48x   z>Hi  i      z>16xBcirculartopologylinear)r	   r   r
   r   r   r   r   r   ranger   r   r   r   featuresappendr   splitnameiddescriptionannotations)r   r   packetr   
seq_lengthsequencerecordnum_featuresioffsetfeature_datastartendr&   r!   has_namehas_commentversionlocationr'   r4   commentfeature	num_sites	site_datanum_versionsversionsversion_dataflagscircularityr   r   r   _parseE   s   









rO   c                       s(   e Zd ZdZ fddZdd Z  ZS )GckIteratorzParser for GCK files.c                    s   t  j|ddd dS )z+Break up a GCK file into SeqRecord objects.bGCK)modefmtN)super__init__)selfsource	__class__r   r   rV      s   zGckIterator.__init__c                 C   s   t |}|S )zStart parsing the file, and return a SeqRecord generator.

        Note that a GCK file can only contain one sequence, so this
        iterator will always return a single record.
        )rO   )rW   r   recordsr   r   r   parse   s   zGckIterator.parse)__name__
__module____qualname____doc__rV   r\   __classcell__r   r   rY   r   rP      s    rP   N)r`   structr   Bio.Seqr   Bio.SeqFeaturer   r   Bio.SeqRecordr   
Interfacesr   r   r   r   r   rO   rP   r   r   r   r   <module>   s    