ó
Y_Sc           @@ sp   d  Z  d d l m Z m Z d d l Td d l Td Z d Z d Z d d „ Z
 d d	 „ Z d
 „  Z d „  Z d S(   sÂ  Read and write a rectangular array of sequence data.
    
One sequence per line and nothing else. Each line must contain the same number
of characters. Blank lines and white space are ignored.
 
--- Example Array ---

--------------------------LENSTSPYDYGENESD-------FSDSPPCPQDF
--------------------------LENLEDLF-WELDRLD------NYNDTSLVENH-
--------------------------MSNITDPQMWDFDDLN-------FTGMPPADEDY
-----------------------------------YTSDN---------YSGSGDYDSNK
-SL-------NFDRTFLPALYSLLFLLGLLGNGAVAAVLLSQRTALSSTDTFLLHLAVAD
--LC-PATMASFKAVFVPVAYSLIFLLGVIGNVLVLVILERHRQTRSSTETFLFHLAVAD
-SPC-MLETETLNKYVVIIAYALVFLLSLLGNSLVMLVILYSRVGRSVTDVYLLNLALAD
-EPC-RDENVHFNRIFLPTIYFIIFLTGIVGNGLVILVMGYQKKLRSMTDKYRLHLSVAD
i    (   t   absolute_importt   print_functioni   (   t   *sé  
--------------------------LENSTSPYDYGENESD-------FSDSPPCPQDF
--------------------------LENLEDLF-WELDRLD------NYNDTSLVENH-
--------------------------MSNITDPQMWDFDDLN-------FTGMPPADEDY
-----------------------------------YTSDN---------YSGSGDYDSNK
-SL-------NFDRTFLPALYSLLFLLGLLGNGAVAAVLLSQRTALSSTDTFLLHLAVAD
--LC-PATMASFKAVFVPVAYSLIFLLGVIGNVLVLVILERHRQTRSSTETFLFHLAVAD
-SPC-MLETETLNKYVVIIAYALVFLLSLLGNSLVMLVILYSRVGRSVTDVYLLNLALAD
-EPC-RDENVHFNRIFLPTIYFIIFLTGIVGNGLVILVMGYQKKLRSMTDKYRLHLSVAD
t   arrayt   flatfilec         C@ s,   g  t  |  | ƒ D] } | ^ q } t | ƒ S(   s  Read a file of raw sequence alignment data. 

    Args:
        fin -- A stream or file to read
        alphabet -- The expected alphabet of the data, if given
    Returns: 
        SeqList -- A list of sequences
    Raises: 
        ValueError -- If the file is unparsable
    (   t   iterseqt   SeqList(   t   fint   alphabett   st   seqs(    (    sA   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/corebio/seq_io/array_io.pyt   read>   s    "c         c@ sð   t  | ƒ } d } x× t |  ƒ D]É \ } } | j ƒ  r= q n  | j ƒ  } | d d k rl t d | ƒ ‚ n  t | ƒ } | j | ƒ s£ t d | | | f ƒ ‚ n  | rÎ | t | ƒ k rÎ t d | ƒ ‚ n  t | ƒ } t | | ƒ Vq Wd S(   s/   Read one line of sequence data and yield the sequence.

    Args:
        fin -- A stream or file to read
        alphabet -- The expected alphabet of the data, if given    
    Yeilds: 
        Seq -- One alphabetic sequence at a time.
    Raises: 
        ValueError -- If the file is unparsable
    i    t   >s   Parse Error on input line: %d s.   Character on line: %d not in alphabet: %s : %ss%   Line %d has an incommensurate length.N(	   t   Alphabett	   enumeratet   isspacet   stript
   ValueErrort   remove_whitespacet
   alphabetict   lent   Seq(   R   R   t   line_lengtht   linenumt   line(    (    sA   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/corebio/seq_io/array_io.pyR   M   s$     c         C@ s"   x | D] } t  |  | ƒ q Wd S(   s‰   Write raw sequence data, one line per sequence.

    arguments:
        afile -- A writable stream.
        seqs  -- A list of Seq's
    N(   t   writeseq(   t   afileR
   R	   (    (    sA   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/corebio/seq_io/array_io.pyt   writer   s    c         C@ s   t  | d |  ƒd S(   s    Write a single sequence in raw format.

    arguments:
        afile -- A writable stream.
        seq  -- A Seq instance
    t   fileN(   t   print(   R   t   seq(    (    sA   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/corebio/seq_io/array_io.pyR   }   s    N(   s   arrayR   (    (   t   __doc__t
   __future__R    R   R   t   utilst   examplet   namest
   extensionst   NoneR   R   R   R   (    (    (    sA   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/corebio/seq_io/array_io.pyt   <module>*   s   

%	