
    Ri"#                     ~    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 G d de      Zy)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                 b    | j                  |      }t        |      |k  rt        d| d      |S )z9Read the specified number of bytes from the given stream.zCannot read z bytes from stream)readlen
ValueErrorstreamlengthdatas      G/home/agent/.friday_env/lib/python3.12/site-packages/Bio/SeqIO/GckIO.py_readr      s6    ;;vD
4y6<x/ABCCK    c                     | j                  d      }t        |      dk(  ryt        |      dk  rt        d      t        d|      d   }t	        | |      }|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.
       r   Nz#Cannot read packet size from stream>I)r   r   r   r   r   r   s      r   _read_packetr      sY     [[^F
6{a
6{Q>??D&!!$F DKr   c                 r    t        | d      }t        d|      d   }t        | |      j                  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   3   =    
 61FD&!!$F ''0DKr   c                 r    t        | d      }t        d|      d   }t        | |      j                  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                   ,     e Zd ZdZdZ fdZd Z xZS )GckIteratorzParser for GCK files.bc                     t         |   |d       | j                  j                  d      }|st	        d      t        |      dk  rt	        d      y)zBreak up a GCK file into SeqRecord objects.

        Note that a GCK file can only contain one sequence, so this
        iterator will always return a single record.
        GCK)fmt   zEmpty file.z1Improper header, cannot read 24 bytes from streamN)super__init__r   r   r   r   )selfsourcer   	__class__s      r   r)   zGckIterator.__init__N   sW     	U+ {{#]++t9r>PQQ r   c                 t   | j                   }t        |      }|t        t        d|d d       d   }|t	        |      dz
  kD  rt        d      |dd  j                  d      }t        t        |            }t        |      }|t        d      t        |      }|t        d      t        d|d d       \  }}|t	        |      k7  rt        d      t	        |      dz
  |d	z  k7  rt        d
      t        |      D ]  }d|d	z  z   }|||d	z    }	t        d|	      \  }
}}}}}}|dk(  rd}nd}t        |
||      }|dkD  rd}nd}i }|dkD  rt        |      }|g|d<   |dkD  rt        |      }|g|d<   |dkD  r}t        |||      }|j                  j                  |        t        |      }|t        d      t        d|d d       \  }}t	        |      dz
  |dz  k7  rt        d      t        |      D ]>  }d|dz  z   }|||dz    }t        d|      \  }
}}}|rt        |       |s4t        |       @ t        |      }|t        d      t!        |d      }t        d|      d   }t!        ||dz        }t        |      D ]2  }|dz  }|||dz    }t        d|dd        d   }|dkD  s(t        |       4 t!        |d       t        |      }|j#                  d      d   x|_        |_        ||_        t!        |d      }t        d|      d   }|dkD  rd|j*                  d <   |S d!|j*                  d <   |S )"Nr   r   r   z"Conflicting sequence length valuesr   zPremature end of filez>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   StopIterationr   r   r   r   r   r   ranger   r   r    r   featuresappendr   splitnameiddescriptionannotations)r*   r   packet
seq_lengthsequencerecordnum_featuresioffsetfeature_datastartendr6   r1   has_namehas_commentversionlocationr7   rE   commentfeature	num_sites	site_datanum_versionsversionsversion_dataflagscircularitys                                r   __next__zGckIterator.__next__`   s   f%> D&!*-a0
 Fa'ABB!":$$W-3x=) f%>455 f%>455%+E6"1:%>"\ X&ABBv;?lR//K  |$ ,	,ARZF!&6B;7L JP%|JFUCvxg {
 %eS@H ax% J!|$V,'+f
7#Q(0&-Y
6" { LGOO""7+Y,	,f f%>455"(r
";Yv;?i"n,RSSy! 
	'ARZFv4I28	2R/UC; f%v&
	' f%>455 VQ'dL1!4!34|$ 	'AWF#FVc\:L !|BC'89!<KQv&	' 	fc V$"&**S/!"44fi!
 fb!We,Q/?-7Fz*  .6Fz*r   )__name__
__module____qualname____doc__modesr)   r`   __classcell__)r,   s   @r   r"   r"   I   s    ER$Tr   r"   N)rd   structr   Bio.Seqr   Bio.SeqFeaturer   r   Bio.SeqRecordr   
Interfacesr	   r   r   r   r    r"    r   r   <module>rm      sA      % ) # ((k" kr   