
    Xf}                         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	 Zd
 Zd Zd Zd Z G 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                 |    |                      |          }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datas      /lib/python3.11/site-packages/Bio/SeqIO/GckIO.py_readr      sC    ;;vD
4yy6BBBBCCCK    c                 v    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   s      r   _read_packetr      s@     61FD&!!!$F  D&>r   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   s      r   _read_pstringr   /   I    
 61FD&!!!$F  ''00DKr   c                     t          | d          }t          d|          d         }t          | |                              d          }|S )zcRead a 32-bit Pascal string.

    Similar to a Pascal string but length is encoded on 4 bytes.
    r   r   r   r   r   r   s      r   _read_p4stringr    :   r   r   c              #     K   |                      d          }|st          d          t          |          dk     rt          d          t          |           \  }}t	          d|d d                   d         }||dz
  k    rt          d          |dd                              d          }t          t          |                    }t          |            t          |           \  }}t	          d	|d d
                   \  }}|t          |          k    rt          d          |d
z
  |dz  k    rt          d          t          |          D ]}d
|dz  z   }	||	|	dz            }
t	          d|
          \  }}}}}}}|dk    rd}nd}t          |||          }|dk    rd}nd}i }|dk    rt          |           }|g|d<   |dk    rt          |           }|g|d<   |dk    rt          |||          }|j                            |           t          |           \  }}t	          d	|d d
                   \  }}|d
z
  |dz  k    rt          d          t          |          D ]N}d
|dz  z   }	||	|	dz            }t	          d|          \  }}}}|rt          |            |rt          |            Ot          |            t          | d          }t	          d|          d         }t          | |dz            }t          |          D ]G}|dz  }	||	|	dz            }t	          d|dd                    d         }|dk    rt          |            Ht          | d           t          |           }|                    d          d         x|_        |_        ||_        t          | d          }t	          d |          d         }|dk    rd!|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,   r9   commentfeature	num_sites	site_datanum_versionsversionsversion_dataflagscircularitys                                 r   _parserT   E   s      ;;r??D ('''
4yy2~~LMMM!&))NFF fRaRj))!,J FQJ=>>>abbz  ))Hs8}}%%F  "&))NFF!'vbqbz!:!:Z S]]""=>>>z\B&&&TUUU<   ,( ,(QVfv{23 FL!<F
 F
BT68[' Q;;FF
 F!%V<<< !88DD!D 
a<< ((D#'&Jw??$V,,G")Jv Q;;XDZHHHw'''' "&))NFF$UF2A2J77ZzY^##NOOO9 
# 
#QV6FRK/0	.4]I.N.N+X{  	"&!!! 	#6"""  ##L$--a0LV\C/00H<   # #S# 56 T<#455a8??6"""
 
&#   D"jjooa00FK&)F
 &"E%((+KQ)3:&&)1:&
LLLLLr   c                   (     e Zd ZdZ fdZd Z xZS )GckIteratorzParser for GCK files.c                 P    t                                          |dd           dS )z+Break up a GCK file into SeqRecord objects.bGCK)modefmtN)super__init__)selfsource	__class__s     r   r]   zGckIterator.__init__   s(    cu55555r   c                 $    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.
        )rT   )r^   r   recordss      r   parsezGckIterator.parse   s     ..r   )__name__
__module____qualname____doc__r]   rc   __classcell__)r`   s   @r   rV   rV      sM        6 6 6 6 6      r   rV   N)rg   structr   Bio.Seqr   Bio.SeqFeaturer   r   Bio.SeqRecordr   
Interfacesr	   r   r   r   r    rT   rV    r   r   <module>ro      s                % % % % % % ) ) ) ) ) ) # # # # # # ( ( ( ( ( (         Q Q Qh    "     r   