ó
™62Pc           @   s8   d  Z  d d l Td Z d	 Z d d „ Z d d „ Z d S(
   sÂ  Reads Sequences in interleaved Phylip format (not sequential) and returns a
list of sequences. Phylip is a very common phylogeny generating sequence type
that has the following traits:
1) First line contains number of species and number of characters in a species'
sequence. Options may follow, and they can be spaced or unspaced. Options are
simply letters such as A and W after the number of characters.
2) Options don't have to contain U in order for a usertree to appear.
3) If there are options then options appear first, then the sequences. For the
first iteration of sequences the first ten spaces are reserved for names of
options and species, the rest is for sequences.
4) For the second and following iterations the names are removed, only
sequence appears
4) At end of file a usertree may appear. First there is a number that indicts
the number of lines the usertree will take, and then the usertrees follow.

Examples:
  6   50   W
W         0101001111 0101110101 01011	
dmras1    GTCGTCGTTG GACCTGGAGG CGTGG	
hschras   GTGGTGGTGG GCGCCGGCCG TGTGG
ddrasa    GTTATTGTTG GTGGTGGTGG TGTCG
spras     GTAGTTGTAG GAGATGGTGG TGTTG
scras1    GTAGTTGTCG GTGGAGGTGG CGTTG
scras2    GTCGTCGTTG GTGGTGGTGG TGTTG

0101001111 0101110101 01011	
GTCGTCGTTG GACCTGGAGG CGTGG	
GTGGTGGTGG GCGCCGGCCG TGTGG
GTTATTGTTG GTGGTGGTGG TGTCG
GTAGTTGTAG GAGATGGTGG TGTTG
GTAGTTGTCG GTGGAGGTGG CGTTG
GTCGTCGTTG GTGGTGGTGG TGTTG

1					
((dmras1,ddrasa),((hschras,spras),(scras1,scras2)));


iÿÿÿÿ(   t   *t   phylipt   phyc         C   s   t  t |  | ƒ ƒ S(   s'   Iterate over the sequences in the file.(   t   itert   read(   t   fint   alphabet(    (    sN   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/seq_io/phylip_io.pyt   iterseqG   s    c         C   s£  g  } g  } d } d } d } d } d } d }	 |  j  ƒ  }
 xµ|
 ró|
 j ƒ  } | g  k r` n„| d j ƒ  r½ t | ƒ d k r½ t | ƒ | k r½ t | d ƒ | k r½ t | d ƒ } n'|	 d k rt | ƒ | k  r| d d | k rü |	 d 8}	 qt d ƒ ‚ qä|	 d 8}	 nÌ| d k rZt | | d ƒ | k rK| d 8} qät d ƒ ‚ nŠ| d j ƒ  rt | ƒ d k ròt | ƒ d k ròt | d ƒ } t | d ƒ } t | ƒ d k rþd j | d ƒ } t | ƒ | j d ƒ }	 qþqät d ƒ ‚ nã |	 d k rä| d k r(t d	 ƒ ‚ qä| | k  rä| t | ƒ k r| j d j |
 d
 j ƒ  ƒ ƒ | j |
 d d
 !j	 ƒ  ƒ | d 7} n# | | c d j | ƒ 7<| d 7} | | k rád } t | ƒ | j d ƒ }	 qáqän  |  j  ƒ  }
 q? Wt | ƒ t | ƒ k st | ƒ | k r-t d ƒ ‚ n  g  } xc t
 d t | ƒ ƒ D]L } t | | ƒ | k r‰| j t | | | | | ƒ ƒ qIt d ƒ ‚ qIWt | ƒ S(   Ni    t    i   s#   Not an option, but it should be ones   User Tree in Wrong Placei   t   Us   parse errors"   Empty File, or possibly wrong filei
   s#   Number of different sequences wrongs   extra sequence in list(   t   readlinet   splitt   isdigitt   lent   intt
   ValueErrort   joint   countt   appendt   stript   ranget   Seqt   SeqList(   R   R   t   sequencet   identst   num_seqt   num_total_seqt   trackert   usertree_trackert   optionst   num_optionst   linet   s_linet   seqst   i(    (    sN   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/seq_io/phylip_io.pyR   N   sv    	J


$ 
"*$N(   R   (   R   (   t   __doc__t   corebio.seqt   namest
   extensionst   NoneR   R   (    (    (    sN   /home/CIBIV/huy/public_html/EpiSpeller/weblogo-3.2/corebio/seq_io/phylip_io.pyt   <module>@   s
   
