mς
°=΅Dc           @   sν  d  Z  d Z d Z y e Wn d< \ Z Z n Xy d k Z d k Z d k Z d k Z d k	 Z	 e i
 i e i
 i e	 i e i    d d d   e e e i
  Z d	 k l Z l Z Wn1 y e i i d
 e  Wn e GHn X  n Xe i
 i e i d  d Z e i
 i e  d Z e i d  i e  i   Z d   Z d   Z d   Z d k Z e  e i! d   p e Z" d Z# d d d d g Z$ d g Z% d d d d d d d d d d d  d! d" d# g Z& d$ d d% d& d' d( d) d* d+ d, d- d. d/ d0 g Z' e i d1  Z( d2   Z) d3   Z* d4   Z+ d5   Z, d6   Z- e. d7 j o e Z/ e i d Z0 e e j oR yD e1 e0  o3 e2 d8 e0 d  o e i d Z/ e i d9 Z0 n Wq½q½Xn e2 d: e/ e e3 e0   f  p d; GHn d S(=   sΫ   packgene.py -- IFF format for standardization of 2bit gene compression...

   eventual goal is to merge both competing formats into one...
   IFF format data from http://en.wikipedia.org/wiki/Interchange_File_Format
   s>  
    packgene -- create compressed gene data in standard IFF format
    Copyright (C) 2005  John Comeau <jc.jcomeau.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    s7   Not all needed libraries found, upgrade or check path: i   i    Ni   t   libt   python(   s   gpls	   jclicenses   %s
s   [0-9A-Za-z]+c          G   s   t  S(   N(   t   False(   t   whatever(    (    t   ./packgene.pyt
   DebugPrint4   s    c          G   s΄   |  \ } } t |  t i j o t |  } n t t d  o | i	 |  Sn^ d } xP t d t |   D]9 } | | | } | t |  d j o | | } qo qo W| Sd S(   s   for pythons without str.joint   joint    i    i   N(   t   argst   stringt   arrayt   typet   typest
   StringTypet   evalt   hasattrt   strR   t   joinedt   ranget   lent   index(   R   R   R	   R   R
   (    (    R   R   7   s       c          G   sg   |  \ } } t |  p
 d } n t d d  o | i |  Sn  t i t i	 |   i |  Sd S(   s   for pythons without str.splitR   t   splitN(
   R   R	   t   string_to_splitR   t   NoneR   R   t   ret   compilet   escape(   R   R	   R   (    (    R   R   E   s      
t   LONGFORMi2   t   GATCgatcNnMRt   TCAGtcagNnMRs   TCAGtcagNn-URYKMs   UCAGucagNn-TRYKMt   2BITs   CAT t   FORMt   LISTt   AUTHt   ANNOt   BODYt   NAMEt   PROPt   VERSs   (c) t   CODEt   PACKs   SEQ t   SIZEs   LONGCAT t   LONGLISTs   AUTHOR  t   ANNOTATEs   BODY    s   NAME    t   PROPERTYs   VERSION s   (c)     t   PACKCODEt   PACKTYPEt   SEQUENCEt   ORIGSIZEs   [\W]+c          G   s)   t  i i d |  d  t  i d  d S(   s   issue error message and croaks   %s
i    i   N(   t   syst   stderrt   writeR   t   exit(   R   (    (    R   t   die   s     c    	      G   s>  t  o t t d
 t t   } n t t d
 t t   } t |  t |   d j  o t
 d t  n t |   } | i   } d
 } | d j o t i } n$ | i d  p t | d  } n xr | D]j } d } t |  } xO | i   D]A } | i d  o t i | d  d	 } n t | | |  qρ WqΜ Wd
 S(   s)   pack FASTA file into 2bit IFF format filei   s   Usage: %s INFILE [...] OUTFILEt   -s   *.t   wbR   t   >i   i    N(   R   t   dictt   mapR   t   ifft   longifft   headersR   R   R   R5   t   selft   listt   filest   popt   outfilet   outputR1   t   stdoutt
   startswitht   opent   infilet   namet   inputt	   readlinest   linet	   namesplitR   (	   R   RI   RG   R@   RB   RK   RH   R=   RC   (    (    R   t   packgene   s.      
    c          G   s7   t  |  d  } t o
 d } n d } t i | |  S(   s5   pack number into big-endian 32-bit int or 64-bit longi    s   >Qs   >LN(   t   longR   t   lengthR   t   formatt   structt   pack(   R   RP   RO   (    (    R   t
   packlength   s      
c          G   s+   t  o
 d } n d } t i | |  d  S(   s"   unpack length number from IFF files   >Qs   >Li    N(   R   RP   RQ   t   unpackR   (   R   RP   (    (    R   t   unpacklength₯   s
      
c          G   s   x |  D] } t | d  } d } xm | i pb | i d  } | d j oB | d d d g j o" t i	 i
 d |  | i   q d } q% q% Wq Wd	 S(
   s&   dump out (intelligently?) any IFF filet   rbt   fetch_groupidi   R   R    s   CAT s   %s not an IFF file
t   fetch_filelengthN(   R   t   fileRF   RI   t   statet   closedt   readt   idR1   R2   R3   t   close(   R   RZ   RY   RI   R]   (    (    R   t   iffscan«   s       
t   __main__s   type(%s) == types.FunctionTypei   s   %s%sR   (   i   i    (4   t   __doc__t	   Copyrightt   errormessaget   TrueR   R1   t   osR   R   t   pwdt   patht   appendR   t   getpwuidt   geteuidt   reprt   com.jcomeaut   gplt	   jclicenseR2   R3   R   t   argvR>   t   splitextt   commandR   t   searcht   groupt   originalselfR   RQ   t   boolt   getenvR   t
   LINELENGTHt   packstringst   filetypeR;   R<   RL   R5   RM   RS   RU   R_   t   __name__t   functionR   R   R   t   tuple(    R{   Rb   R<   Ry   R   Rm   RU   RQ   R>   R   R   RM   Rx   Rd   Rw   Rt   R   R1   R_   Rf   R   R   R   R5   Rc   R   R;   Rn   Rq   RS   RL   Re   (    (    R   t   ?   sZ   -5				
		00					"" 