σ
Y_Sc           @@ sv   d  Z  d d l m Z m Z d d l Td d l m Z d Z d Z d Z	 d d	  Z d d
  Z d   Z d   Z d S(   s  Read and write raw, unformatted sequence data. The whole file is read 
in as a sequence.  Whitespace is removed.


--- Example Plain/Raw/Text File ---

--------------------------LENSTSPYDYGENESD-------FSDSPPCPQDF
--------------------------LENLEDLF-WELDRLD------NYNDTSLVENH-
--------------------------MSNITDPQMWDFDDLN-------FTGMPPADEDY
-----------------------------------YTSDN---------YSGSGDYDSNK
-SL-------NFDRTFLPALYSLLFLLGLLGNGAVAAVLLSQRTALSSTDTFLLHLAVAD
--LC-PATMASFKAVFVPVAYSLIFLLGVIGNVLVLVILERHRQTRSSTETFLFHLAVAD
-SPC-MLETETLNKYVVIIAYALVFLLSLLGNSLVMLVILYSRVGRSVTDVYLLNLALAD
-EPC-RDENVHFNRIFLPTIYFIIFLTGIVGNGLVILVMGYQKKLRSMTDKYRLHLSVAD
i    (   t   absolute_importt   print_functioni   (   t   *(   t   remove_whitespacesΛ  
--------------------------LENSTSPYDYGENESD-------FSDSPPCPQDF
--------------------------LENLEDLF-WELDRLD------NYNDTSLVENH-
--------------------------MSNITDPQMWDFDDLN-------FTGMPPADEDY
-----------------------------------YTSDN---------YSGSGDYDSNK
-SL-------NFDRTFLPALYSLLFLLGLLGNGAVAAVLLSQRTALSSTDTFLLHLAVAD
--LC-PATMASFKAVFVPVAYSLIFLLGVIGNVLVLVILERHRQTRSSTETFLFHLAVAD
-SPC-MLETETLNKYVVIIAYALVFLLSLLGNSLVMLVILYSRVGRSVTDVYLLNLALAD
-EPC-RDENVHFNRIFLPTIYFIIFLTGIV
t   plaint   rawc         C@ s,   g  t  |  |  D] } | ^ q } t |  S(   s  Read a file of raw sequence 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/plain_io.pyt   read=   s    "c         c@ sΟ   t  |  } g  } x t |   D] \ } } | j   r= q n  | j   } | d d k rl t d |   n  t |  } | j |  s£ t d | | | f   n  | j |  q Wt d j	 |  |  Vd S(   s6   Read the sequence data and yield one (and only one) sequence.

    Args:
        fin -- A stream or file to read
        alphabet -- The expected alphabet of the data, if given    
    Yields: 
        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 : %st    N(
   t   Alphabett	   enumeratet   isspacet   stript
   ValueErrorR   t
   alphabetict   appendt   Seqt   join(   R   R	   t   linest   linenumt   line(    (    sA   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/corebio/seq_io/plain_io.pyR   L   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/plain_io.pyt   writen   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/plain_io.pyR   y   s    N(   s   plains   raw(    (   t   __doc__t
   __future__R    R   R    t   utilsR   t   examplet   namest
   extensionst   NoneR   R   R   R   (    (    (    sA   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/corebio/seq_io/plain_io.pyt   <module>)   s   
"	