ó
gbc           @   s&   d  d l  Z  d e f d „  ƒ  YZ d S(   iÿÿÿÿNt   EcoPCRDBAnnotationWriterc           B   sG   e  Z d  Z d d d d „ Z d „  Z d „  Z d d „ Z d „  Z RS(	   sÞ   
    Class used to write Annotation description in EcoPCRDB format.
    
    EcoPCRDBAnnotationWriter is oftenly called through the EcoPCRDBSequenceWriter class
    
    @see: L{ecopcr.sequence.EcoPCRDBSequenceWriter}
    i   t   CDSc   	      C   s  | |  _  | |  _ | |  _ d | | f |  _ t |  j d ƒ |  _ d |  _ d | } t | d ƒ } t t d | t
 t | ƒ ƒ ƒ ƒ |  _ | j t j d t | ƒ ƒ ƒ x$ | D] } | j |  j | ƒ ƒ q² W| j ƒ  d |  _ |  j j t j d |  j ƒ ƒ d S(   s}  
        class constructor
        
        @param dbname: name of ecoPCR database
        @type dbname: C{str}
        @param id: name of the qualifier used as feature id
        @type id: C{str}
        @param fileidx:
        @type fileidx: C{int}
        @param type:
        @type type: C{list} or C{tuple}
        @param definition: 
        @type definition: C{str}
        s   %s_%03d.adxt   wbi    s   %s.fdxs   > IN(   t   _typet   _definitiont   _idt	   _filenamet   opent   _filet   _sequenceIdxt   dictt   mapt   Nonet   xranget   lent
   _fttypeidxt   writet   structt   packt   _ecoFtTypePackert   closet   _annotationCount(	   t   selft   dbnamet   idt   fileidxt   typet
   definitiont   ftnamet   ftt   t(    (    s9   lib/python2.7/site-packages/obitools/ecopcr/annotation.pyt   __init__   s    				
'
	c         C   sK   t  | ƒ } t j d | | | ƒ } t  | ƒ | d k sG t d ƒ ‚ | S(   Ns   > I %dsi   s   error in feature type packing(   R   R   R   t   AssertionError(   R   R   t	   totalSizet   packed(    (    s9   lib/python2.7/site-packages/obitools/ecopcr/annotation.pyR   3   s    "c         C   sô   | j  d } | j } |  j | j } | j ƒ  } | |  j d } |  j | k rf | |  j d } n d } | d  k	 s„ t d ƒ ‚ t	 | ƒ }	 d |	 }
 t
 j d |	 |
 | | | | t | ƒ | |	 | ƒ
 } t	 | ƒ |
 d k sð t d ƒ ‚ | S(   Ni   i    t    s*   Only strand defined features can be storedi   i   s   > I I I I I 20s I %dss   error in annotation packingi   i   i   i   i(   i,   (   t   begint   endR   t   ftTypet   isDirectR   R   R   R    R   R   R   t   int(   R   t   featuret   seqidxR$   R%   R   t   strandR   R   t	   deflengthR!   R"   (    (    s9   lib/python2.7/site-packages/obitools/ecopcr/annotation.pyt   _ecoAnnotationPacker;   s.    	
		"c         C   s‚   | d  k r' |  j } |  j d 7_ n  xT | j ƒ  D]F } | j |  j k r4 |  j d 7_ |  j j |  j | | ƒ ƒ q4 q4 Wd  S(   Ni   (	   R   R	   t   getFeatureTableR&   R   R   R   R   R-   (   R   t   sequenceR*   R)   (    (    s9   lib/python2.7/site-packages/obitools/ecopcr/annotation.pyt   put\   s    	c         C   sC   |  j  j d d ƒ |  j  j t j d |  j ƒ ƒ |  j  j ƒ  d  S(   Ni    s   > I(   R   t   seekR   R   R   R   R   (   R   (    (    s9   lib/python2.7/site-packages/obitools/ecopcr/annotation.pyt   __del__e   s    N(	   t   __name__t
   __module__t   __doc__R   R   R   R-   R0   R2   (    (    (    s9   lib/python2.7/site-packages/obitools/ecopcr/annotation.pyR       s   '		!	(   R   t   objectR    (    (    (    s9   lib/python2.7/site-packages/obitools/ecopcr/annotation.pyt   <module>   s   